-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Problematic type inference in supercall when type parameter appears only in contravariant position #2218
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
Minimization: trait Rule[In]
class C {
def ruleWithName[In](f: In => Int): Rule[In] =
new DefaultRule(f) {}
class DefaultRule[In](f: In => Int) extends Rule[In]
} An intersection type is not necessary, any |
Minimized further to not use a function type, the important part is that the type parameter has to appear in contravariant positions only: trait Rule[In]
trait Contra[-T]
class C {
def ruleWithName[In](f: Contra[In]): Rule[In] =
new DefaultRule(f) {} // Inference works if the "{}" is removed.
class DefaultRule[In](f: Contra[In]) extends Rule[In]
} |
We can desugar the anonymous class to see that the problem is with the type inference of the superclass constructor of the anonymous class: trait Rule[In]
trait Name
trait Contra[-T]
class C {
def ruleWithName[In](f: Contra[In]): Rule[In] = {
class Hi extends DefaultRule(f) // T=Nothing instead of T=In
new Hi
}
class DefaultRule[T](f: Contra[T]) extends Rule[T]
} |
Note that |
Fix #2218: Add fullyDefinedType for class parent types
Following code compiles fine in Scalac, but fails to compile in Dotty, because the type parameter inferred is
new DefaultRule[Nothing, Out, A, X](f) with Name
.If we remove the intersection type, the following version compiles fine in Dotty:
Note that adding variance doesn't help, following version also fails:
The text was updated successfully, but these errors were encountered: