Closed
Description
Compiler version
3.0.1-RC1
Minimized code
trait Super[T <: Number]:
def get: T
class Sub extends Super[Integer]:
override def get: Integer = ???
Output (OK?)
$ javap Sub.scala
public class Sub implements Super<java.lang.Integer> {
public Sub();
public java.lang.Integer get();
public java.lang.Number get();
}
Expectation
That duplicate 'get' method seems suspicious to me, I had expected:
$ javap Sub.scala
public class Sub implements Super<java.lang.Integer> {
public Sub();
public java.lang.Integer get();
}
... however in fact both Scala and Java appear to select the correct method just fine.
Minimized code
Adding static object forwarders to the mix, however:
trait Super[T <: Number]:
def get: T = ???
object Sub extends Super[Integer]:
override def get: Integer = 37
Output
$ javap Sub.class
public final class Sub {
public static java.lang.Integer get();
public static java.lang.Number get();
}
Expectation
Here I expected:
$ javap Sub.class
public final class Sub {
public static java.lang.Integer get();
}
And in this case it actually leads to a problem: while Scala code will not use these forwarders anyway, when using them from Java:
public class Use {
public static void main(String... args) {
System.out.println(Sub.get());
}
}
I get a "reference to get is ambiguous" error from javac (tested with AdoptOpenJDK-11.0.11+9 - interestingly OpenJDK 1.8.0_272-b10 appears to select the right method just fine).
(of course this is a minimized example, but we see this problem when building Akka with Scala 3 and referring to Akka extensions from Java code)