bug
bug copied to clipboard
overloading curried function in Scala 2?
class Test:
def foo(x: String)(y: Int): Int = ???
def foo(x: String)(y: Double): Int = ???
This is allowed in Scala 3 , should this be ported to Scala 2?
class Test {
def foo(x: String)(y: Int): Int = ???
def foo(x: String)(y: Double): Int = ???
}
Is not allowed in Scala 2.
The failure comes at the use site:
scala 2.13.8> (new Test).foo("foo")(3)
^
error: ambiguous reference to overloaded definition,
both method foo in class Test of type (x: String)(y: Double): Int
and method foo in class Test of type (x: String)(y: Int): Int
match argument types (String)
I haven't studied this, but offhand, it doesn't seem like the kind of change we're making anymore in Scala 2. Has anyone looked into what it would take to change it...?
I commented that the motivation according to the ref was extension methods (where the first param list is just the receiver). I am curious whether there is interaction with type interference. Also this would surely be a -Xsource:3.
I don't know how Scala 3 does it - would be interesting if someone can summarize :) As far as I can tell, type checking (and overload resolution as part of it) in Scala 2 works one param list at the time, so it might be quite a deep change.