Skip to content

Crash on SAM conversion from contextual lambda #23234

Closed
@prolativ

Description

@prolativ

Compiler version

3.3.6, 3.7.0

Minimized code

abstract class MyFun:
  def apply(x: Int): Int

object Test:
  val myFun: MyFun = (x: Int) ?=> x + 10

Output (click arrow to expand)

unhandled exception while running erasure on /tmp/SAM.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: /tmp/SAM.scala
        during phase: erasure
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.16
    compiler version: version 3.7.0
            settings: -classpath /Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.7.0/scala3-library_3-3.7.0.jar:/Users/mpalka/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.16/scala-library-2.13.16.jar -d /Users/mpalka/Library/Caches/ScalaCli/virtual-projects/18/project-2465964a/.scala-build/tmp_080867dde4/classes/main -sourceroot /Users/mpalka/Library/Caches/ScalaCli/virtual-projects/18/project-2465964a

Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.core.Types$RefinedType$.apply(Types.scala:3264)
        at dotty.tools.dotc.core.TypeOps$.addRefinement$1(TypeOps.scala:435)
        at dotty.tools.dotc.core.TypeOps$.$anonfun$6(TypeOps.scala:443)
        at scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
        at scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
        at scala.collection.immutable.List.foldLeft(List.scala:79)
        at dotty.tools.dotc.core.TypeOps$.classBound(TypeOps.scala:443)
        at dotty.tools.dotc.core.TypeOps$AvoidMap.apply(TypeOps.scala:478)
        at dotty.tools.dotc.core.TypeOps$$anon$2.apply(TypeOps.scala:571)
        at dotty.tools.dotc.core.TypeOps$.avoid(TypeOps.scala:575)
        at dotty.tools.dotc.typer.Typer.ensureNoLocalRefs(Typer.scala:1547)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1509)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3568)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3648)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3725)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3730)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3841)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1493)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3568)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3648)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3725)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3730)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3841)
        at dotty.tools.dotc.typer.Typer.$anonfun$66(Typer.scala:2952)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2952)
        at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:972)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3542)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3647)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3725)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3730)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3752)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3798)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3220)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1061)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3548)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3552)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3647)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3725)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3730)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3752)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3798)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3353)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3594)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3648)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3725)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3730)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3841)
        at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:145)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:383)
        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:376)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:367)
        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:1324)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:360)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:407)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:407)
        at scala.Function0.apply$mcV$sp(Function0.scala:42)
        at dotty.tools.dotc.Run.showProgress(Run.scala:469)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:407)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:419)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:419)
        at dotty.tools.dotc.Run.compileSources(Run.scala:306)
        at dotty.tools.dotc.Run.compile(Run.scala:291)
        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)

Expectation

Instead of crashing, the compiler should report an error. Either just a simple type mismatch between Int ?=> Int and MyFun or a more hinted message about SAM conversion not performed because of using a contextual lambda rather than a plain one

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions