Skip to content

Compiler crash with for-comprehension #22505

Open
@martinberger

Description

@martinberger

Compiler version

3.6.2

Minimized code

package Tests

def combineNaive[A, B](f: (A) => Option[B])(l: List[List[A]]): List[B] =
    val tmp: List[B] = for (
      i <- (0 to l.size - 1);
//       j <- (i + 1 to l.size - 1);
      a <- (0 to l(i).size - 1);
//      b   <- (0 to l(j).size - 1);
      res <- f(l(i)(a))
    ) yield res
    tmp.toList

Note:

  • The problem occurs only when I compile the code with sbt in VS Code. If compile that code with scalac I get a type error but no compiler crash.
  • If I remove the commented lines, the compiler still crashes.
  • If I change tmp.toList in the last line to tmp the compiler also still crashes.

Output (click arrow to expand)

sbt:Martin Berger> clean
[success] Total time: 0 s, completed 3 Feb 2025, 19:58:50
sbt:Martin Berger> compile
[info] compiling 1 Scala source to /Users/martinberger/zettelkasten/cs/saturation_prover/new-code/target/scala-3.6.2/classes ...
[info] 
[info]   exception occurred while typechecking /Users/martinberger/zettelkasten/cs/saturation_prover/new-code/src/main/scala/Tests.scala
[info] 
[info]   An unhandled exception was thrown in the compiler.
[info]   Please file a crash report here:
[info]   https://github.com/scala/scala3/issues/new/choose
[info]   For non-enriched exceptions, compile with -Xno-enrich-error-messages.
[info] 
[info]      while compiling: /Users/martinberger/zettelkasten/cs/saturation_prover/new-code/src/main/scala/Tests.scala
[info]         during phase: typer
[info]                 mode: Mode(ImplicitsEnabled)
[info]      library version: version 2.13.15
[info]     compiler version: version 3.6.2
[info]             settings: -Xkind-projector "" -Xmigration AnyScalaVersion -classpath /Users/martinberger/zettelkasten/cs/saturation_prover/new-code/target/scala-3.6.2/classes:/Users/martinberger/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.6.2/scala3-library_3-3.6.2.jar:/Users/martinberger/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.15/scala-library-2.13.15.jar -d /Users/martinberger/zettelkasten/cs/saturation_prover/new-code/target/scala-3.6.2/classes -deprecation true -explain true -explain-types true -feature true -indent true -language List(strictEquality) -new-syntax true -print-lines true -source 3.7
[error] ## Exception when compiling 1 sources to /Users/martinberger/zettelkasten/cs/saturation_prover/new-code/target/scala-3.6.2/classes
[error] java.lang.AssertionError: assertion failed
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:119)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$.dotty$tools$dotc$printing$Texts$Text$$_$print$$anonfun$1(Texts.scala:130)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:334)
[error] dotty.tools.dotc.printing.Texts$Text.print(Texts.scala:128)
[error] dotty.tools.dotc.printing.Texts$Text.mkString(Texts.scala:143)
[error] dotty.tools.dotc.core.Decorators$.show(Decorators.scala:248)
[error] dotty.tools.dotc.printing.Showable.show(Showable.scala:23)
[error] dotty.tools.dotc.printing.Showable.show$(Showable.scala:9)
[error] dotty.tools.dotc.ast.Trees$Tree.show(Trees.scala:52)
[error] dotty.tools.dotc.reporting.TypeMismatch.$anonfun$1(messages.scala:359)
[error] scala.Option.map(Option.scala:242)
[error] dotty.tools.dotc.reporting.TypeMismatch.explain(messages.scala:359)
[error] dotty.tools.dotc.reporting.Message.explanation$$anonfun$1(Message.scala:376)
[error] dotty.tools.dotc.reporting.Message.inMessageContext(Message.scala:368)
[error] dotty.tools.dotc.reporting.Message.explanation(Message.scala:376)
[error] dotty.tools.xsbt.DelegatingReporter.doReport(DelegatingReporter.java:53)
[error] dotty.tools.dotc.reporting.Reporter.issueUnconfigured(Reporter.scala:160)
[error] dotty.tools.dotc.reporting.Reporter.go$1(Reporter.scala:191)
[error] dotty.tools.dotc.reporting.Reporter.issueIfNotSuppressed(Reporter.scala:210)
[error] dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:213)
[error] dotty.tools.dotc.report$.error(report.scala:69)
[error] dotty.tools.dotc.typer.ErrorReporting$.errorType(ErrorReporting.scala:32)
[error] dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:23)
[error] dotty.tools.dotc.typer.ErrorReporting$.errorTree(ErrorReporting.scala:26)
[error] dotty.tools.dotc.typer.ErrorReporting$Errors.typeMismatch(ErrorReporting.scala:201)
[error] dotty.tools.dotc.typer.Typer.recover$1(Typer.scala:4624)
[error] dotty.tools.dotc.typer.Typer.adaptToSubType$1(Typer.scala:4650)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:4454)
[error] dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4534)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4767)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:4036)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3773)
[error] dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2834)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3475)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
[error] dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1427)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1431)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3504)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3581)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3773)
[error] dotty.tools.dotc.typer.Typer.$anonfun$66(Typer.scala:2897)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2897)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3478)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3160)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3484)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3488)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3580)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3684)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3730)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3293)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3530)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3581)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3658)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3662)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3773)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:507)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
[error] dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
[error] scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
[error] scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
[error] scala.collection.immutable.List.prependedAll(List.scala:152)
[error] scala.collection.immutable.List$.from(List.scala:685)
[error] scala.collection.immutable.List$.from(List.scala:682)
[error] scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:396)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:282)
[error] dotty.tools.dotc.Run.compile(Run.scala:267)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:196)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:252)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:186)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:166)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:241)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:166)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:214)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:542)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:542)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$3(Incremental.scala:182)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$3$adapted(Incremental.scala:180)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:458)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:117)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:413)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:500)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:400)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:208)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:542)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:496)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:433)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2443)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2393)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:41)
[error] sbt.internal.io.Retry$.apply(Retry.scala:47)
[error] sbt.internal.io.Retry$.apply(Retry.scala:29)
[error] sbt.internal.io.Retry$.apply(Retry.scala:24)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:41)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2391)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] sbt.Execute.work(Execute.scala:292)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[error] java.base/java.lang.Thread.run(Thread.java:1575)
[error]            
[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) java.lang.AssertionError: assertion failed
[error] Total time: 0 s, completed 3 Feb 2025, 19:58:51

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions