Scala Programming Language
  1. Scala Programming Language
  2. SI-5617

Provide a more helpful error message than "overrides nothing" when "override" is used but nothing is overridden

    Details

      Description

      The error messages related to inheritance are generally pretty decent, if arguments are the same:

      trait A { def foo: Int }
      trait B extends A { override def foo: String }
      
      <console>:8: error: overriding method foo in trait A of type => Int;
       method foo has incompatible type
             trait B extends A { override def foo: String }
                                              ^
      

      But if arguments differ, the error message is not very helpful:

      trait A { def foo(i: Int): Int }
      trait B extends A { override def foo(s: String): Int }
      
      <console>:8: error: method foo overrides nothing
             trait B extends A { override def foo(s: String): Int }
                                              ^
      

      It would be nice if in case of an error, the compiler would check if there is a signature with the same name, but different arguments.

      The code in questions is here: https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala#L756

      As far as I know Paul has some code implementing Levenshtein difference, so maybe it could even check for similar names (for typos)?
      E. g. something like `hasSimilarName(inclazz: Symbol, member: Symbol, levenshteinDifference: Int = 0)`

        Activity

        Hide
        Adriaan Moors added a comment -

        Jason, could you take a look at this?

        Show
        Adriaan Moors added a comment - Jason, could you take a look at this?
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/731
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/commit/6aea0ae

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Simon Ochsenreither
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development