Repository navigation
Closed
Description
Minimization is due to paulp,
object WhatsYourTypeIsMyType {
class TypeCheat[+T] { type MyType = T }
class Foo {
val tc = new TypeCheat[Foo]
var x: tc.MyType = _
def setX() = x = new Foo
}
class Bar extends Foo {
override val tc = new TypeCheat[Bar]
def unsound = this
setX()
println(x.unsound)
}
def main(args: Array[String]): Unit = new Bar
}Compiles and when run produces a CCE,
iles@lewis:scala$ scala-master -classpath . WhatsYourTypeIsMyType
java.lang.ClassCastException: WhatsYourTypeIsMyType$Foo cannot be cast to WhatsYourTypeIsMyType$Bar
at WhatsYourTypeIsMyType$Bar.<init>(bug.scala:14)
at WhatsYourTypeIsMyType$.main(bug.scala:16)
at WhatsYourTypeIsMyType.main(bug.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:71)
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:139)
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:71)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:139)
at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Activity
scabug commentedon Oct 24, 2012
Imported From: https://issues.scala-lang.org/browse/SI-6566?orig=1
Reporter: @milessabin
Affected Versions: 2.9.2, 2.10.0-RC1
scabug commentedon Oct 24, 2012
@milessabin said:
Related, and simpler,
scabug commentedon Oct 24, 2012
@paulp said:
Here's another way of looking at it:
I was amazed to see this had gone undiscovered for so long, but then I saw it's a regression... from scala 2.7. Same failure in 2.8 and beyond, but in 2.7 it makes the seemingly correct observation that
scabug commentedon Dec 10, 2012
@retronym said:
scala/scala@68bcc9e7
scabug commentedon Dec 10, 2012
@retronym said:
Only one failure in
partest --pos --negafter that patch.See also:
scala/scala@8a6e20ce
Which introduced the test that now reports two errors rather than one:
scabug commentedon Dec 10, 2012
@paulp said:
I notice just now this is related to #5120. In both tickets there is an invariant type parameter, and an abstract type which is derived from the type parameter. A loss of fidelity in that derivation allows the "invariant" type to vary, and unsoundness results. In #5120 the lever is how existentials are simplified, and here the lever is variance checking. Since abstract types can be used in many more ways than type parameters (by virtue of being members, and because they can be referenced from subclasses and from the outside) and because they are considerably less fully exercised than type parameters, I think it likely we have more variations on this theme to discover.
scabug commentedon Dec 10, 2012
@odersky said:
I am not 100% sure what caused the change from 2.7 to 2.8. There must have been a reason, but I don't remember it. The reversal that Jason proposes looks certainly safe. So I'd say let's do it now, and watch out whether something major stops compiling.
scabug commentedon Dec 11, 2012
@retronym said:
retronym/scala@scala:2.10.x...retronym:ticket/6656
https://scala-webapps.epfl.ch/jenkins/job/scala-checkin-manual/696/console
If that goes well, I'll ask Josh to run a community build. We can then choose whether we want to ship the fix on master or 2.10.x.
scabug commentedon Dec 11, 2012
@retronym said:
I retract my unfounded optimism.
scabug commentedon Jan 2, 2013
@paulp said:
Patch pending.
scabug commentedon Jan 22, 2013
@adriaanm said:
fixed for 2.11.0-M1 in a419799f87
scabug commentedon Feb 1, 2013
@paulp said:
Can't see how to fix it for 2.10. Here's the commit message I just wrote for the partial backport.
scabug commentedon Feb 16, 2014
@Blaisorblade said:
To be sure, the issue is that S and T in Fun must be invariant, right? But not in Fun0.
I hope this bug is linked in the release notes.
I proposed the following spec update — scala/scala-dist#131. It seems the issue was not discussed at all.
scabug commentedon Feb 16, 2014
@Blaisorblade said:
I also updated the comment in scala/scala#3537.
I was also trying to refine the spec documenting the current behavior (which is questionable, but I hope it approximates what should be documented to guarantee soundness), and/or comparing what's implemented with the current spec, but I had to give up on that.
scabug commentedon Feb 17, 2014
@retronym said:
@paolo: The release notes will contain a list of all fixed bugs. But to highlight particular changes, we can also add a section to: https://github.com/scala/make-release-notes/blob/master/hand-written.md. Would you like to submit a PR for that?
scabug commentedon Feb 17, 2014
@Blaisorblade said:
Sounds good. I will look for a suitable phrasing.
scabug commentedon Feb 17, 2014
@Blaisorblade said:
scala/make-release-notes#46
I also added "specification" as component, since scala/scala-dist#131 is still open. (I'm not sure whether to reopen the bug, but I'll better leave the judgment call to you guys).
scabug commentedon Mar 21, 2014
@adriaanm said:
See also #7093 on an important note regarding protected[this].