-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Behavior of overloaded varargs and default parameter value differs from Scala 2 #14765
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
My vote or guess is that it should drop the application requiring default args before considering specificity. I think Scala 2 is doing that correctly? |
That looks like a Scala 2 bug to me. The spec in https://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#overloading-resolution says:
(and the most specific one is chosen). In this case the second vararg method can be applied to a single argument, but the first method with the default argument cannot be applied to a variable number of |
Before that, it says,
Both are applicable, so take the set of alternatives which don't employ any default argument in the application. That will exclude the alternative selected in Scala 3. |
Ah, yes, that explains it. We don't implement that step in Scala 3 anymore. I am not sure we should. It seems to be a needless complication of the rules. But we should at least document the difference. |
Compiler version
3.1.2-RC1
down to3.0.0
Minimized code
Output
Prints:
1
in Scala 32
in Scala 2Expectation
Expected the behavior to remain the same as in Scala 2.
This may be intended, but it looks like a regression to me (that could potentially break things silently).
The text was updated successfully, but these errors were encountered: