-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Handle Scalac variance unsoundness with regards to constructors. #926
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
Conversation
The idea is that whenever Dotty detects a migration problem under -language:Scala2, it should issue a migration warning, so we know what needs to be rewritten.
The included test pos-special/variances-constr.scala 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.
@@ -500,7 +500,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { | |||
projection.name == tpnme.hkApply && | |||
!other.isHKApply && | |||
other.testLifted(projection.prefix.LambdaClass(forcing = true).typeParams, | |||
if (inOrder) isSubType(projection.prefix, _) else isSubType(_, projection.prefix), | |||
{ xx => println(i"test lifted with $xx") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
println
left in code.
needed to turn some errors into warnings.
LGTM. I checked out this branch to test that: class C[+A] { class Inner { def this(a: A) = this() } } // only allowed under the migration I do see an seemingly spurious warning about procedure syntax, is that a known issue?
This version is correctly allowed: class C[+A] { def this(a: A) = this() } During my testing, I also noticed another difference wrt scalac: class C[A] { class A } // sandbox/test.scala:1: error: A is already defined as type A |
The procedure syntax warning seems to be a bug. I'll follow up on this. On Fri, Nov 6, 2015 at 10:07 PM, Jason Zaugg [email protected]
Martin Odersky |
Handle Scalac variance unsoundness with regards to constructors.
See SI-9549 for a summary. Review by @retronym