Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scabug opened this issue Mar 27, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Mar 27, 2012

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)

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 27, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5617?orig=1
Reporter: @soc
Other Milestones: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 11, 2012

@adriaanm said:
Jason, could you take a look at this?

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 17, 2012

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 21, 2012

@scabug scabug closed this Jun 21, 2012
@scabug scabug added this to the 2.10.0-M4 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.