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

scabug opened this Issue Mar 7, 2017 · 1 comment


None yet
2 participants
Copy link

scabug commented Mar 7, 2017


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):


(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.


This comment has been minimized.

Copy link

scabug commented Mar 7, 2017

Imported From:
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