Skip to content

Compiler crashes with a combination of context function and extends AnyVal #22752

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

Closed
lenguyenthanh opened this issue Mar 9, 2025 · 3 comments · Fixed by #23015
Closed

Compiler crashes with a combination of context function and extends AnyVal #22752

lenguyenthanh opened this issue Mar 9, 2025 · 3 comments · Fixed by #23015

Comments

@lenguyenthanh
Copy link

Compiler version

I tried with 3.3.0, 3.3.5, 3.6.4 and 3.nightly

Minimized code

//> using scala 3.nightly
// if we removed `extends AnyVal` it works
class Inner(body: Int ?=> Int) extends AnyVal:
  // this needs to be context function to makes compiler crashes
  def rescue: Int ?=> Int = ???

Output (click arrow to expand)

unhandled exception while running erasure on {retracted}/compiler-crash.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: {retracted}/scripts/compiler-crash.scala
    during phase: erasure
            mode: Mode(ImplicitsEnabled)
 library version: version 2.13.16
compiler version: version 3.7.0-RC1-bin-20250308-133dcb3-NIGHTLY-git-133dcb3
        settings: -classpath {retracted}/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.7.0-RC1-bin-20250308-133dcb3-NIGHTLY/scala3-library_3-3.7.0-RC1-bin-20250308-133dcb3-NIGHTLY.jar:{retracted}/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.16/scala-library-2.13.16.jar -d /{retracted}/.scala-build/scripts_84160669fb-59de36a8e6/classes/main -sourceroot {retracted}/scripts

Exception in thread "main" scala.MatchError: Apply(Ident(rescue$extension),List(This(Ident(Inner)))) (of class dotty.tools.dotc.ast.Trees$Apply)
at dotty.tools.dotc.transform.Erasure$Typer.skipContextClosures$1(Erasure.scala:952)
at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:954)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3555)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3657)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3735)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3740)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3762)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3808)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3236)
at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1061)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3561)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3565)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3657)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3735)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3740)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3762)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3808)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3369)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3607)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3658)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3735)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3740)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3851)
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:346)
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:339)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:386)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:386)
at scala.Function0.apply$mcV$sp(Function0.scala:42)
at dotty.tools.dotc.Run.showProgress(Run.scala:448)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:386)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:398)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
at dotty.tools.dotc.Run.compileUnits(Run.scala:398)
at dotty.tools.dotc.Run.compileSources(Run.scala:285)
at dotty.tools.dotc.Run.compile(Run.scala:270)
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.mai

@lenguyenthanh lenguyenthanh added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 9, 2025
@Gedochao Gedochao added area:erasure and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 10, 2025
@odersky
Copy link
Contributor

odersky commented Apr 17, 2025

I think we need to disallow context functions as value class arguments. To do this, we need to edit Checking.checkDerivedValueClass.

@bracevac
Copy link
Contributor

bracevac commented Apr 17, 2025

We should probably forbid value classes for context-function types in the first place. That's not what the mechanism is designed for. Crashing over this is of course not good and requires fixing regardless.

Edit: Martin beat me to it :P

@olhotak
Copy link
Contributor

olhotak commented Apr 17, 2025

Potential spree candidate. @mbovel

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.

6 participants