-
Notifications
You must be signed in to change notification settings - Fork 21
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
Parenless overloaded methods are used in ambiguous cases #9395
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9395?orig=1 |
Ian Bellamy (imbellish) said (edited by @lrytz on Jul 15, 2015 6:16:55 AM UTC):
|
@lrytz said (edited on Jul 15, 2015 6:49:52 AM UTC): object Test extends App {
def f(s: String): String = "1"
val f: (String) => String = s => "2"
val t: String => String = f
println(t("")) // 2
} http://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#overloading-resolution The reference to
If I'm wrong in reading the spec, it would be good to add an example to it explaining this case. |
Dotty says
Is this like the Monty Hall problem where you always pick the other door? |
Sorry I did not note which version of Dotty was current two years ago. Currently, 3.5.2 says Odersky says "as specified" scala/scala3#19654 (comment) There is recent Dotty history of trying to make overload resolution with eta-expansion do something "intuitive". For some people, that may mean " The explanations here are about mechanisms and not specification: The spec says:
The Closing this ticket since further clarifications or progressions will take place at scala3. |
This code:
Prints List(Fixed, Fixed).
The type checker is calling the no-argument variant of my.something(), and then silently taking the return type and passing it to map(). This ignores the other matching one-argument version of my.something.
The below line (arguably correctly) produces a compile error about an "ambiguous reference to overloaded definition":
Adding parentheses to the no-argument definition of the method removes the issue. Changing the return type of the no-argument method to be anything other than String => String removes the issue.
I think this is incorrect behavior; where there is a conflict between the result of an implicit conversion (the my.something() return value) and an unconverted correct type, either the unconverted type should win or a compile error should be thrown telling the user about ambiguity. In other words, the above code should either output List(x_z, y_z) or fail to compile. Currently the implicitly converted version is silently taking precedence.
The text was updated successfully, but these errors were encountered: