-
Notifications
You must be signed in to change notification settings - Fork 21
Fail to resolve overloaded method when type inference is required #10046
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-10046?orig=1 |
Jean-Baptiste Giraudeau (jbgi) said: class Test {
static class Foo<A> {
Foo<A> compose(Foo<A> a) {
return new Foo<>();
}
Bar<A> compose(Bar<A> b) {
return new Bar<>();
}
}
static class Bar<A> {
Bar<A> compose(Foo<A> a) {
return new Bar<>();
}
Bar<A> compose(Bar<A> b) {
return new Bar<>();
}
}
static <A> Bar<A> barA() {
return new Bar<>();
}
public static void main(String[] args) {
Foo<String> fooS = new Foo<>();
// Compile just fine:
fooS.compose(barA());
}
} This kind of limitations means that the scala user-experience (of java 8 libraries in particular) can be inferior to the java user-experience. Resolving regressions vs Java 8 should, imo, be given major priority (at least from a marketing pov ;-)). |
@som-snytt said: Problem statement: scala> class D[A] ; class C[A] { def f(x: C[A]): C[A] = new C[A] ; def f(x: D[A]): D[A] = new D[A] }
defined class D
defined class C
scala> def d[A]: D[A] = new D[A]
d: [A]=> D[A]
scala> new C[String]().f(d)
<console>:14: error: overloaded method value f with alternatives:
(x: D[String])D[String] <and>
(x: C[String])C[String]
cannot be applied to (D[Nothing])
new C[String]().f(d)
^ This is not a workaround. scala> class D[A] ; class C[A] { def f(x: A => C[A]): C[A] = new C[A] ; def f(x: A => D[A]): D[A] = new D[A] }
defined class D
defined class C
scala> def d[A]: D[A] = new D[A]
d: [A]=> D[A]
scala> new C[String]().f(x => d)
<console>:14: error: overloaded method value f with alternatives:
(x: String => D[String])D[String] <and>
(x: String => C[String])C[String]
cannot be applied to (String => D[Nothing])
new C[String]().f(x => d)
^
scala> new C[String]().f(x => d[x.type])
<console>:14: error: overloaded method value f with alternatives:
(x: String => D[String])D[String] <and>
(x: String => C[String])C[String]
cannot be applied to (String => D[_ <: String with Singleton])
new C[String]().f(x => d[x.type])
^ |
Julien Truffaut (julien-truffaut) said: In Typers -> preSelectOverloaded, we could try to remove overloaded candidates that cannot match, e.g. there is no way that a Bar[A] can be a Foo[String]. If we can do that then the issue would be resolved because there would be only one alternative. However, it seems that the Tree barA hasn't been type checked in preSelectOverloaded, so I don't know how to access type information. |
@som-snytt said: |
Julien Truffaut (julien-truffaut) said: |
@som-snytt said: That is 6.26.3. (The table of contents is temporarily pointing to a phantom 2.13 version.) |
#10542 seems similar? |
Here is a snippet to illustrate the problem:
This issue is particularly important for monocle because all optics (Iso, Lens, Prism, ...) compose together which means we need to define 8 different compose methods instead of a single method overloaded 8 times.
The text was updated successfully, but these errors were encountered: