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

inference failure for call to constructor with formal param types bounded by class type parameters #8227

Open
scabug opened this issue Feb 2, 2014 · 3 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 2, 2014

public class C<K, V> {
  public C(C<? extends K, ? extends V> other) {}
  //public C(int i) {} uncomment and a different error appears at the call site, as this is chosen by overload resolution
}
object Test {
  new C(null)
  new E(null)
}

class E[K, V](other: E[_ <: K, _ <: V]) {
}
qbin/scalac sandbox/C.java sandbox/D.scala
sandbox/D.scala:2: error: inferred type arguments [_$2,_$1] do not conform to class C's type parameter bounds [K,V]
  new C(null)
  ^
sandbox/D.scala:3: error: inferred type arguments [_$2,_$1] do not conform to class E's type parameter bounds [K,V]
  new E(null)
  ^
two errors found

Maybe its more a limitation than a bug. The interaction with overloading (silently choosing an alternative) is pretty unfortunate.

@scabug
Copy link
Author

scabug commented Feb 2, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8227?orig=1
Reporter: @retronym
Affected Versions: 2.11.0

@scabug
Copy link
Author

scabug commented Feb 2, 2014

@paulp said:
Fun with when things happen. I guess when you supply type args the monomorphic alternative is cut out of overloading consideration.

scala> new C[T1 forSome { type T1 }, T2 forSome { type T2 }](null)
warning: there were 2 feature warning(s); re-run with -feature for details
res0: C[T1 forSome { type T1 },T2 forSome { type T2 }] = C@3839e07a

scala> new C(null: C[T1 forSome { type T1 }, T2 forSome { type T2 }])
<console>:8: error: type mismatch;
 found   : C[T1 forSome { type T1 },T2 forSome { type T2 }]
 required: Int
              new C(null: C[T1 forSome { type T1 }, T2 forSome { type T2 }])
                        ^

@scabug
Copy link
Author

scabug commented Feb 5, 2014

@retronym said (edited on Feb 5, 2014 7:59:25 PM UTC):
There is only one constructor which in each class; both are polymorphic (because the class has tparams)

Providing type args explicitly sidesteps the inference failure.

It's of course a bit embarrassing that Javac happily lets you omit the typeargs. But maybe it falls into raw-type mode. I wonder: does javac have -Xprint:typer that I can play with?

@scabug scabug added the infer label Apr 7, 2017
@SethTisue SethTisue added this to the Backlog milestone Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants