scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.87k stars 1.06k forks source link

assertion failed: orphan parameter reference during pickling #21558

Open theosotr opened 2 months ago

theosotr commented 2 months ago

Compiler version

3.5.0

Minimized code

class Base
class A[T <: Float](val f: T) extends Base

def test() = {
  m1(new A(m2()));

}

def m1(x: Base) = {}
def m2(p: A[? <: Float] = new A(1.0f)): Int = 1

Output (click arrow to expand)

```scala Exception in thread "main" java.lang.AssertionError: assertion failed: orphan parameter reference: TypeParamRef(T) at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:311) at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:177) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:699) at dotty.tools.dotc.core.tasty.TreePickler.pickleTpt(TreePickler.scala:345) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$3(TreePickler.scala:517) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:517) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:509) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$2(TreePickler.scala:510) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:510) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:554) at dotty.tools.dotc.core.tasty.TreePickler.pickleTreeUnlessEmpty(TreePickler.scala:349) at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:383) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:645) at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:416) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:416) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:681) at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:374) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:647) at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:416) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:416) at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:697) at dotty.tools.dotc.core.tasty.TreePickler.pickle$$anonfun$1(TreePickler.scala:922) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:920) at dotty.tools.dotc.transform.Pickler.run$$anonfun$1$$anonfun$1(Pickler.scala:306) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.transform.Pickler.run$$anonfun$1(Pickler.scala:279) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:278) at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:380) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.immutable.List.foreach(List.scala:334) at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:373) at dotty.tools.dotc.transform.Pickler.runPhase$1(Pickler.scala:392) at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:398) at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323) at dotty.tools.dotc.Run.runPhases$1(Run.scala:336) at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384) at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396) at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69) at dotty.tools.dotc.Run.compileUnits(Run.scala:396) at dotty.tools.dotc.Run.compileSources(Run.scala:282) at dotty.tools.dotc.Run.compile(Run.scala:267) at dotty.tools.dotc.Driver.doCompile(Driver.scala:37) at dotty.tools.dotc.Driver.process(Driver.scala:201) at dotty.tools.dotc.Driver.process(Driver.scala:169) at dotty.tools.dotc.Driver.process(Driver.scala:181) at dotty.tools.dotc.Driver.main(Driver.scala:211) at dotty.tools.MainGenericCompiler$.run$1(MainGenericCompiler.scala:162) at dotty.tools.MainGenericCompiler$.main(MainGenericCompiler.scala:186) at dotty.tools.MainGenericCompiler.main(MainGenericCompiler.scala) ```
Gedochao commented 1 month ago

Full crash output:

error when pickling type T
error when pickling tree T
error when pickling tree new A[T]
error when pickling tree new A[T](Int.int2float(m2(repro$package.m2$default$1)))
error when pickling tree m1(new A[T](Int.int2float(m2(repro$package.m2$default$1))))
error when pickling tree {
  m1(new A[T](Int.int2float(m2(repro$package.m2$default$1))))
}
error when pickling tree def test(): Unit =
  {
    m1(new A[T](Int.int2float(m2(repro$package.m2$default$1))))
  }
error when pickling tree () extends Object() { this: repro$package.type =>
  private def writeReplace(): AnyRef =
    new scala.runtime.ModuleSerializationProxy(classOf[repro$package.type])
  def test(): Unit =
    {
      m1(new A[T](Int.int2float(m2(repro$package.m2$default$1))))
    }
  def m1(x: Base): Unit =
    {
      ()
    }
  def m2(p: A[? >: Nothing <: Float]): Int = 1
  def m2$default$1: A[? <: Float] @uncheckedVariance = new A[T](1.0f)
}
error when pickling tree @SourceFile("repro.scala") final module class repro$package() extends Object() {
   this: repro$package.type =>
  private def writeReplace(): AnyRef =
    new scala.runtime.ModuleSerializationProxy(classOf[repro$package.type])
  def test(): Unit =
    {
      m1(new A[T](Int.int2float(m2(repro$package.m2$default$1))))
    }
  def m1(x: Base): Unit =
    {
      ()
    }
  def m2(p: A[? >: Nothing <: Float]): Int = 1
  def m2$default$1: A[? <: Float] @uncheckedVariance = new A[T](1.0f)
}
error when pickling tree package <empty> {
  final lazy module val repro$package: repro$package = new repro$package()
  @SourceFile("repro.scala") final module class repro$package() extends Object()
     { this: repro$package.type =>
    private def writeReplace(): AnyRef =
      new scala.runtime.ModuleSerializationProxy(classOf[repro$package.type])
    def test(): Unit =
      {
        m1(new A[T](Int.int2float(m2(repro$package.m2$default$1))))
      }
    def m1(x: Base): Unit =
      {
        ()
      }
    def m2(p: A[? >: Nothing <: Float]): Int = 1
    def m2$default$1: A[? <: Float] @uncheckedVariance = new A[T](1.0f)
  }
}

  unhandled exception while running pickler on /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/compiler-repro/repro.scala

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Xno-enrich-error-messages.

     while compiling: /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/compiler-repro/repro.scala
        during phase: pickler
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.14
    compiler version: version 3.5.0
            settings: -classpath /Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.5.0/scala3-library_3-3.5.0.jar:/Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar -d /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/compiler-repro/.scala-build/compiler-repro_473cbde4c4-d9eb8ef26f/classes/main -sourceroot /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/compiler-repro

Exception in thread "main" java.lang.AssertionError: assertion failed: orphan parameter reference: TypeParamRef(T)
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:311)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:177)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:699)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTpt(TreePickler.scala:345)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$3(TreePickler.scala:517)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:517)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:509)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree$$anonfun$2(TreePickler.scala:510)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:510)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:554)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTreeUnlessEmpty(TreePickler.scala:349)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:383)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:645)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:416)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:416)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:681)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:374)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:647)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleStats$$anonfun$2(TreePickler.scala:416)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleStats(TreePickler.scala:416)
        at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:697)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle$$anonfun$1(TreePickler.scala:922)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:920)
        at dotty.tools.dotc.transform.Pickler.run$$anonfun$1$$anonfun$1(Pickler.scala:306)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.transform.Pickler.run$$anonfun$1(Pickler.scala:279)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:278)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:380)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:334)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:373)
        at dotty.tools.dotc.transform.Pickler.runPhase$1(Pickler.scala:392)
        at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:398)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:396)
        at dotty.tools.dotc.Run.compileSources(Run.scala:282)
        at dotty.tools.dotc.Run.compile(Run.scala:267)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:201)
        at dotty.tools.dotc.Driver.process(Driver.scala:169)
        at dotty.tools.dotc.Driver.process(Driver.scala:181)
        at dotty.tools.dotc.Driver.main(Driver.scala:211)
        at dotty.tools.dotc.Main.main(Main.scala)

Reproduced on 3.3.3, 3.5.0, 3.6.0-RC1-bin-20240907-614170f-NIGHTLY-git-614170f

mbovel commented 2 weeks ago

This issue was picked for the Scala Issue Spree of tomorrow, Monday, October 21st. @dwijnand and @HarrisL2 will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.