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

unhandled exception while running erasure, MatchError, Context Function inside implicit class #22211

Open
maksymilianrozanski opened this issue Dec 15, 2024 · 2 comments

Comments

@maksymilianrozanski
Copy link

Compiler version

3.3.4
3.6.2

Minimized code

object Logger {
  case class Ctx(a: String)
  implicit final class MyLoggerInterpolator(private val sc: StringContext) extends AnyVal {
    def error(message: String*): Ctx ?=> Unit = {
      ???
    }
  }
}

In contrast, this similar code compiles correctly:

object Logger {
  case class Ctx(a: String)
  implicit final class MyLoggerInterpolator(private val sc: StringContext) extends AnyVal {
    def error(message: String*)(using Ctx): Unit = {
      ???
    }
  }
}

Output (click arrow to expand)

unhandled exception while running erasure on /tmp/scastie13405439581228603105/src/main/scala/main.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/scastie13405439581228603105/src/main/scala/main.scala
    during phase: erasure
            mode: Mode(ImplicitsEnabled)
 library version: version 2.13.15
compiler version: version 3.6.2
        settings: -bootclasspath /home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.6.2/scala3-library_3-3.6.2.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.15/scala-library-2.13.15.jar -classpath /tmp/scastie13405439581228603105/target/scala-3.6.2/classes:/home/sbtRunnerContainer/.ivy2/local/org.scastie/runtime-scala_3/1.0.0-SNAPSHOT/jars/runtime-scala_3.jar:/home/sbtRunnerContainer/.ivy2/local/org.scastie/api_3/0.30.0-SNAPSHOT/jars/api_3.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/typesafe/play/play-json_3/2.10.0-RC5/play-json_3-2.10.0-RC5.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/typesafe/play/play-functional_3/2.10.0-RC5/play-functional_3-2.10.0-RC5.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.11.4/jackson-core-2.11.4.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.11.4/jackson-annotations-2.11.4.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.11.4/jackson-datatype-jdk8-2.11.4.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.11.4/jackson-datatype-jsr310-2.11.4.jar:/home/sbtRunnerContainer/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.11.4/jackson-databind-2.11.4.jar -d /tmp/scastie13405439581228603105/target/scala-3.6.2/classes -deprecation true -feature true
scala.MatchError: Apply(Apply(Ident(error$extension),List(This(Ident(MyLoggerInterpolator)))),List(Ident(message))) (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:3478)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3160)
	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1061)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3484)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3488)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3160)
	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1061)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3484)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3488)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3160)
	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1061)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3484)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3488)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1085)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3293)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3530)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3581)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3773)
	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:146)
	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.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.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
	at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
	at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
	at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
	at sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
	at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
	at sbt.internal.io.Retry$.apply(Retry.scala:47)
	at sbt.internal.io.Retry$.apply(Retry.scala:29)
	at sbt.internal.io.Retry$.apply(Retry.scala:24)
	at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
	at sbt.Execute.work(Execute.scala:292)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
@maksymilianrozanski maksymilianrozanski added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 15, 2024
@soronpo
Copy link
Contributor

soronpo commented Dec 15, 2024

You do know that you can use extension methods instead, right?

@maksymilianrozanski
Copy link
Author

I didn’t realize that extension methods can be used with StringContext. Thanks!

@Gedochao Gedochao added area:erasure area:implicits related to implicits area:extension-methods and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants