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 while porting from Scala 2 to Scala 3 #19560

Closed
OndrejSpanel opened this issue Jan 29, 2024 · 6 comments · Fixed by #19567
Closed

Compiler crash while porting from Scala 2 to Scala 3 #19560

OndrejSpanel opened this issue Jan 29, 2024 · 6 comments · Fixed by #19567
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug itype:crash stat:needs minimization Needs a self contained minimization
Milestone

Comments

@OndrejSpanel
Copy link
Member

Compiler version

3.3.1 and 3.4.0-RC1

Minimized code

I do not have any. The project is large, uses multiple libraries including macros and the error is not very helpful in finding the source of the error.

Output (click arrow to expand)

[error] java.lang.AssertionError: Cannot change span of EmptyTree
[error] dotty.tools.dotc.ast.Trees$EmptyTree.withSpan(Trees.scala:1067)
[error] dotty.tools.dotc.ast.Trees$EmptyTree.withSpan(Trees.scala:1067)
[error] dotty.tools.dotc.ast.desugar$.patternsToParams$$anonfun$1(Desugar.scala:1610)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.dotc.ast.desugar$.patternsToParams(Desugar.scala:1610)
[error] dotty.tools.dotc.typer.Typer.typedFunctionValue(Typer.scala:1630)
[error] dotty.tools.dotc.typer.Typer.typedFunction(Typer.scala:1416)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3170)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$7(ProtoTypes.scala:509)
[error] dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:432)
[error] dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:510)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:912)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:912)
[error] dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:604)
[error] dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:668)
[error] dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:490)
[error] dotty.tools.dotc.typer.Applications$TypedApply.(Applications.scala:794)
[error] dotty.tools.dotc.typer.Applications$ApplyToUntyped.(Applications.scala:911)
[error] dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1141)
[error] dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:350)
[error] dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:121)
[error] dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:984)
[error] dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1067)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3461)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1078)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1116)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:350)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:121)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3160)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3210)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3437)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1200)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3168)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.typedIf(Typer.scala:1289)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3169)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3374)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3393)
[error] dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1193)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1197)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3168)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3437)
[error] dotty.tools.dotc.typer.Typer.$anonfun$62(Typer.scala:2602)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2602)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3136)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3243)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3347)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3393)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2789)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3148)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3152)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3243)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3347)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3393)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2922)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3194)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3374)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3393)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2922)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3194)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3244)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3321)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3325)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3437)
[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:477)
[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:155)
[error] scala.collection.immutable.List$.from(List.scala:684)
[error] scala.collection.immutable.List$.from(List.scala:681)
[error] scala.collection.IterableOps$WithFilter.map(Iterable.scala:898)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:100)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
[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:337)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:348)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:357)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:357)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:261)
[error] dotty.tools.dotc.Run.compile(Run.scala:246)
[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:193)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[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:419)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
[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:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
[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:1583)
[error]

@OndrejSpanel OndrejSpanel added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 29, 2024
@bishabosha bishabosha added stat:needs minimization Needs a self contained minimization area:desugar Desugaring happens after parsing but before typing, see desugar.scala and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 30, 2024
@bishabosha
Copy link
Member

bishabosha commented Jan 30, 2024

I see the crash is in desugaring a lambda function, however it would really help if you can share any code if possible.

If the code is able to be shared, a GitHub repo with some steps that can reproduce is enough for us to start with

@odersky
Copy link
Contributor

odersky commented Jan 30, 2024

In fact the Desugar code in question clearly has a problem. Let me fix that and we'll see whether that solves it.

odersky added a commit to dotty-staging/dotty that referenced this issue Jan 30, 2024
nicolasstucki added a commit that referenced this issue Jan 30, 2024
@OndrejSpanel
Copy link
Member Author

OndrejSpanel commented Jan 30, 2024

When/how could I test the fix? I am not in any hurry, but if there is anything to report, I would like to do it soon, in case any related problems appear.

@bishabosha bishabosha reopened this Jan 30, 2024
@bishabosha
Copy link
Member

bishabosha commented Jan 30, 2024

Please observe tomorrow for the next nightly release at https://central.sonatype.com/artifact/org.scala-lang/scala3-compiler_3 (they are published around 05:00 CET)

@OndrejSpanel
Copy link
Member Author

OndrejSpanel commented Jan 31, 2024

@nicolasstucki I think I have found a small repro, as after the fix the code which was previously working is now reported as invalid. As the error pointed to a particular code, it was easy to extract.

object Main {
  def main(args: Array[String]): Unit = {
    val a = Seq(0 -> 1, 2 -> 3)
    val c = Seq("A", "B")
    for (((beg, end), c) <- a.lazyZip(a)) yield c
  }
}
  • compiles fine with 3.3.1 or 2.13.14
  • crashes with 3.4.0-RC1
  • produces error with 3.4.1-RC1-bin-20240130-7a5cb6e-NIGHTLY

The error is:

Wrong number of parameters, expected: 2
for (((beg, end), c) <- a.lazyZip(a)) yield c

I am not sure if the error is supposed to happen or not, not understanding all 3.4 deprecations.

It might be related to #18842.

@bishabosha
Copy link
Member

we should mark this as fixed, and open another issue for your problem

@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur pushed a commit that referenced this issue Jun 28, 2024
This might fix #19560.

[Cherry-picked 6e31578]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug itype:crash stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants