You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classC[+A] {
private[this] vary:A= _
defgetY:A= y
classInner(x: A) {
y = x
}
}
objectTest {
defmain(args: Array[String]) = {
valx=newC[String]
valy:C[Any] = x
vali=new y.Inner(1)
vals:String= x.getY
println(s)
}
}
This demonstrates an unsoundness in the variance checking of scalac.
Scalac excludes symbols owned by constructors from the
checking. This is unsound, as can be demonstrated by compiling the test
and observing output of the program run:
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at Test$.main(variances-constr.scala:17)
at Test.main(variances-constr.scala)
Dotty allows this code only under -language:Scala2 and issues a migration warning.
The text was updated successfully, but these errors were encountered:
@retronym said:
I guess the "ignore usages in constructors" rule was intended to allow a constructor to accept parameters of the type a covariant type parameter of a directly enclosing class.
Consider:
This demonstrates an unsoundness in the variance checking of scalac.
Scalac excludes symbols owned by constructors from the
checking. This is unsound, as can be demonstrated by compiling the test
and observing output of the program run:
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at Test$.main(variances-constr.scala:17)
at Test.main(variances-constr.scala)
Dotty allows this code only under -language:Scala2 and issues a migration warning.
The text was updated successfully, but these errors were encountered: