Skip to content

ambiguous static forwarders for overridden methods #13039

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

Closed
raboof opened this issue Jul 9, 2021 · 2 comments
Closed

ambiguous static forwarders for overridden methods #13039

raboof opened this issue Jul 9, 2021 · 2 comments

Comments

@raboof
Copy link
Contributor

raboof commented Jul 9, 2021

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)

@smarter
Copy link
Member

smarter commented Jul 9, 2021

Can you try with a nightly? (scalaVersion := "3.0.2-RC1-bin-20210708-7627583-NIGHTLY"), #12860 should have fixed this.

@smarter smarter closed this as completed Jul 9, 2021
@raboof
Copy link
Contributor Author

raboof commented Jul 9, 2021

Can you try with a nightly? (scalaVersion := "3.0.2-RC1-bin-20210708-7627583-NIGHTLY"), #12860 should have fixed this.

Confirmed, both on the reproducer and on the Akka build!

finaglehelper pushed a commit to twitter/util that referenced this issue Aug 10, 2021
Problem:

The Scala 3.0.1 compiler includes bugs that are patched
in the 3.0.2-RC1 release. An example of this is the broken
Java APIs in JDK 11 for our `TimeLikeOps` classes because of
scala/scala3#13039.

Result / Solution:
Using the 3.0.2-RC1 release doesn't break any tests and our
projects compile fine. Let's update to this to make use of the bug
fixes until the 3.0.2 is officially released.

The new Dotty scaladoc requires network access due to a bug
scala/scala3#13272. For now let's
disable scaladoc for scala 3.

JIRA Issues: CSL-11235

Differential Revision: https://phabricator.twitter.biz/D720887
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants