Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler crash when using CanThrow #20206

Closed
alexandru opened this issue Apr 16, 2024 · 4 comments · Fixed by #20210
Closed

Compiler crash when using CanThrow #20206

alexandru opened this issue Apr 16, 2024 · 4 comments · Fixed by #20210

Comments

@alexandru
Copy link

Compiler version

3.4.1

Minimized code

#!/usr/bin/env -S scala-cli shebang

//> using scala "3.4.1"
//> using option -experimental

trait MyEvidence

type ContextFn[+T] = (MyEvidence, CanThrow[Exception]) ?=> T

class Foo:
    def foo: ContextFn[String] =
        "foo"

class Bar:
    val foo = new Foo

    def bar: ContextFn[String] =
        foo.foo +
        "bar"

Output

Compiling project (Scala 3.4.1, JVM (21))
Error compiling project (Scala 3.4.1, JVM (21))
Error: Unexpected error when compiling directio_5eb7d97420-5bb168c9c8: java.lang.AssertionError: assertion failed: bad adapt for this.foo().foo: (using x$1: MyEvidence): String
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.transform.Erasure$Boxing$.adaptToType(Erasure.scala:391)
	at dotty.tools.dotc.transform.Erasure$Typer.adapt(Erasure.scala:1091)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3088)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:843)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3113)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3088)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:843)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3113)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
	at dotty.tools.dotc.typer.Typer.$anonfun$62(Typer.scala:2603)
	at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2603)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:960)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3095)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3300)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3346)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2790)
	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1049)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3101)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3105)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3300)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3346)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2923)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3147)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:354)
	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:333)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:360)
        ....
@alexandru alexandru added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 16, 2024
@Gedochao
Copy link
Contributor

Full crash output:

 exception while retyping this.foo.foo.apply of class Select # -1

  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 -Yno-enrich-error-messages.

     while compiling: /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/.scala-build/compiler-repro_ed26d7ea58-c6d3736935/src_generated/main/repro-script.scala
        during phase: MegaPhase{elimErasedValueType, pureStats, vcElideAllocations, etaReduce, arrayApply, elimPolyFunction, tailrec, completeJavaEnums, mixin, lazyVals, memoize, nonLocalReturns, capturedVars}
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.4.1
            settings: -classpath /Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.4.1/scala3-library_3-3.4.1.jar:/Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -d /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/.scala-build/compiler-repro_ed26d7ea58-c6d3736935/classes/main -experimental true -java-output-version 17 -sourceroot /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro

Exception in thread "main" java.lang.AssertionError: assertion failed: bad adapt for this.foo().foo: (using x$1: repro$minusscript$_.this.MyEvidence): String
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.Erasure$Boxing$.adaptToType(Erasure.scala:391)
        at dotty.tools.dotc.transform.Erasure$Typer.adapt(Erasure.scala:1091)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3088)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:843)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3113)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:671)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3088)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:843)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3113)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
        at dotty.tools.dotc.typer.Typer.$anonfun$62(Typer.scala:2603)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2603)
        at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:960)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3095)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3300)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3346)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2790)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1049)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3101)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3105)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3300)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3346)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2790)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1049)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3101)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3105)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3196)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3300)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3346)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1073)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2923)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3147)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3197)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3274)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3278)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3389)
        at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:354)
        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:333)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:360)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
        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:337)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:360)
        at dotty.tools.dotc.Run.compileSources(Run.scala:261)
        at dotty.tools.dotc.Run.compile(Run.scala:246)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:196)
        at dotty.tools.dotc.Driver.process(Driver.scala:164)
        at dotty.tools.dotc.Driver.process(Driver.scala:176)
        at dotty.tools.dotc.Driver.main(Driver.scala:206)
        at dotty.tools.dotc.Main.main(Main.scala)
Compilation failed

@Gedochao Gedochao added itype:crash area:experimental area:transform and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 17, 2024
@hamzaremmal
Copy link
Member

Minimization:

//> using options -experimental -Yno-experimental

import language.experimental.erasedDefinitions

erased trait A
trait B

def foo: (A, B) ?=> Nothing = ???
def bar: (A, B) ?=> Nothing = foo

It has nothing to do specifically with CanThrow. If you remove erased for A, or if the return type of foo is either A ?=> Nothing or B ?=> Nothing, it works.

@hamzaremmal
Copy link
Member

Changing the signature of foo to A ?=> B ?=> Nothing crashes too for the same reason.

For now, I was able to narrow it down to the computation of integrateSelect in ContextFunctionResults

@odersky odersky self-assigned this Apr 17, 2024
@odersky
Copy link
Contributor

odersky commented Apr 17, 2024

@hamzaremmal I wanted to take a look at it, but see you already have fixed it. That was fast!

hamzaremmal added a commit that referenced this issue Apr 17, 2024
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants