Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-6566

Bodies of non-private type aliases must be invariant

    Details

      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)
      

        Attachments

          Issue Links

            Activity

            Hide
            pggiarrusso Paolo G. Giarrusso added a comment -

            I also updated the comment in https://github.com/scala/scala/pull/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.

            Show
            pggiarrusso Paolo G. Giarrusso added a comment - I also updated the comment in https://github.com/scala/scala/pull/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.
            Hide
            retronym Jason Zaugg added a comment -

            @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?

            Show
            retronym Jason Zaugg added a comment - @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?
            Hide
            pggiarrusso Paolo G. Giarrusso added a comment -

            Sounds good. I will look for a suitable phrasing.

            Show
            pggiarrusso Paolo G. Giarrusso added a comment - Sounds good. I will look for a suitable phrasing.
            Hide
            pggiarrusso Paolo G. Giarrusso added a comment -

            https://github.com/scala/make-release-notes/pull/46

            I also added "specification" as component, since https://github.com/scala/scala-dist/pull/131 is still open. (I'm not sure whether to reopen the bug, but I'll better leave the judgment call to you guys).

            Show
            pggiarrusso Paolo G. Giarrusso added a comment - https://github.com/scala/make-release-notes/pull/46 I also added "specification" as component, since https://github.com/scala/scala-dist/pull/131 is still open. (I'm not sure whether to reopen the bug, but I'll better leave the judgment call to you guys).
            Hide
            moors Adriaan Moors added a comment -

            See also SI-7093 on an important note regarding protected[this].

            Show
            moors Adriaan Moors added a comment - See also SI-7093 on an important note regarding protected [this] .

              People

              • Assignee:
                extempore Paul Phillips
                Reporter:
                milessabin Miles Sabin
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: