-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow overloading a method with a signature which matches before erasure but not after #597
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
Comments
They do, given current defition of
AFAIK that's intentional. We stopped assuming that return type is part of signature for duplicate detection |
No, the erased("if ctx.erasedTypes") signature is different (because it looks at the return value), the non-erased signature is the same (because it only look at the parameters). But Checking#checkNoDoubleDefs is run before erasure. |
@smarter after erasure we need to treat those methods as different, due to bridge generation for example. |
Indeed several parts in the frontend rely on this behavior of signatures. E.g. when looking things up, we merge ethods (decide they override instead of overload) based on their parameter signature. Since it is not a big loss to disallow these things I beleive we should do that. @smarter can you do a PR that changes the error message from (both definitions have the same erased type signature) to (the definitions have matching type signatures)? |
Fix #597: Improve double def error message
This works in scala but not in dotty:
It fails with:
Even though they don't have the same erased type signature.
The problem is that the following code in
Checking#checkNoDoubleDefs
:if (decl.signature matches other.signature) {
Is run before erasure, and
matches
is defined as:Simply changing the code in
Checking#checkNoDoubleDefs
is probably not enough to fix that since the compiler complains:And changing
Signature#matches
to always match the whole signature and not just the params breaks everything in a way I don't understand:We could also choose to not support this kind of overloading, but it is needed to compile Function.scala:
@odersky : What do you think?
The text was updated successfully, but these errors were encountered: