Skip to content

Compiler crashes in ExpandSAMs phase #15855

Closed
@m2ym

Description

@m2ym

Compiler version

$ sbt "print scalaVersion"
[snip]
scala3-library / scalaVersion
        3.2.0-RC3
scala3-interfaces / scalaVersion
        3.2.0-RC3
tasty-core / scalaVersion
        3.2.0-RC3
scala3-sbt-bridge / scalaVersion
        3.2.0-RC3
scala3-compiler / scalaVersion
        3.2.0-RC3
scalaVersion
        3.2.0-RC3
$ java -version
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Debian-1deb11u1, mixed mode, sharing)
$ git log -n 1 | cat
commit e560c2d6970c864ceea5607597d74cf49c443965
Merge: 44a2f7292f 40c4fe3d8c
Author: Paweł Marks <pmarks@virtuslab.com>
Date:   Fri Aug 5 07:35:30 2022 -0700

    Merge pull request #15825 from tgodzik/dont-drop-type-params

    bugfix: Retain partial type params typying information on error

Minimized code

// crash.scala
import scala.language.implicitConversions

class MyFunction(args: String*)

trait MyFunction0[+R] extends MyFunction {
  def apply(): R
}

implicit def fromFunction0[R](f: Function0[R]): MyFunction0[R] = () => f()

Output

$ sbt "scalac crash.scala"
[snip]
exception occurred while compiling crash.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:169)
        at dotty.tools.dotc.ast.tpd$.ClassDef(tpd.scala:309)
        at dotty.tools.dotc.ast.tpd$.AnonClass(tpd.scala:370)
        at dotty.tools.dotc.ast.tpd$.AnonClass(tpd.scala:352)
        at dotty.tools.dotc.transform.ExpandSAMs.transformBlock(ExpandSAMs.scala:63)
        at dotty.tools.dotc.transform.MegaPhase.goBlock(MegaPhase.scala:740)
        at dotty.tools.dotc.transform.MegaPhase.goBlock(MegaPhase.scala:741)
        at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:450)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:298)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:248)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
        at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:255)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:425)
        at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:438)
        at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:379)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:382)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:454)
        at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:466)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:311)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:312)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:234)
        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:1328)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:245)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:253)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:262)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:262)
        at dotty.tools.dotc.Run.compileSources(Run.scala:186)
        at dotty.tools.dotc.Run.compile(Run.scala:170)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)
java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none> while compiling crash.scala
[error] Nonzero exit code returned from runner: 1
[error] (scala3-compiler / Compile / runMain) Nonzero exit code returned from runner: 1
[error] Total time: 2 s, completed 2022/08/14 18:36:16

Expectation

dotc doesn't crash.

Notes

  • Scala 3.1.3 is also facing this issue
  • I have extracted the minimized code from scala-js's library code
    • So, you will face the same issue when you try to compile scala-js library with dotty

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions