Skip to content
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

CLONE - "Ambiguous reference to overloaded definition"... not ambiguous to Java, only to Scala #10219

Closed
scabug opened this issue Mar 7, 2017 · 1 comment

Comments

@scabug
Copy link

scabug commented Mar 7, 2017

Given

class X
class Y extends X
object Ambiguous {
  def f(x: X) = 1
  def f(ys: Y*) = 2
}
scala> Ambiguous.f(new X)
res2: Int = 1

scala> Ambiguous.f(new Y)
<console>:8: error: ambiguous reference to overloaded definition,
both method f in object Ambiguous of type (ys: Y*)Int
and  method f in object Ambiguous of type (x: X)Int
match argument types (Y)
       Ambiguous.f(new Y)

But the corresponding Java program works compiles:

edit: as pointed out by andrew (comment below), javac picks the first alternative in both cases.

public class AmbiguousJ {
    static int f(X x) { return 1; }
    static int f(Y... y) { return 2; }
    public static void main(String[] args) {
        System.out.println(f(new X()));
        System.out.println(f(new Y()));
    }
}

prints (when running):

1
1

(Assuming that X.class and Y.class already exist from compiling the Scala example.)

This is a PITA because X and Y, in my case, are JPA APIs, which I use a lot.

@scabug
Copy link
Author

scabug commented Mar 7, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10219?orig=1
Reporter: sean Lau (sean)
Affected Versions: 2.9.0, 2.10.0
Clones #4728

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