-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extension method with default argument fails to construct #14278
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
The problem comes from a combination of overloading, currying, and default arguments. It has nothing to do with extension methods. For instance: class Foo
object Test {
def patch2(foo: Foo)(arg : List[Int], arg2 : Int = 0) : Unit = {}
def patch2(foo: Foo)(arg : Int) : Unit = patch2(foo)(List(arg))
} fails with
Scala 2.13 also fails here:
Maybe the advice (requirement?) should be that overloaded curried methods (which includes extension methods) cannot have default arguments. |
Or the advice could be to use implicit classes, since we don't have the problem there. It's incorrect to compare Scala 2.13 according to how extension methods are desugared. Scala 2.13 has implicit classes and that is what extension methods are meant to replace. From user perspective I do not care about the desugaring. I care about expressiveness. |
I don't think default args should break this case. If one alternative is applicable, then it is selected; if more than one is applicable, then alternatives requiring default args are discarded. Edit: changed in #14775 |
[skip community_build] closes scala#14278
Compiler version
v3.1.1-RC2
Minimized code
https://scastie.scala-lang.org/MiSpvFT0SKygDNEJdezOzQ
Output
Expectation
No error.
The text was updated successfully, but these errors were encountered: