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

Overlapping patches crash when using -rewrite and compiletime.testing.typeCheckErrors #21415

Closed
WojciechMazur opened this issue Aug 22, 2024 · 0 comments · Fixed by #21547
Closed

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Aug 22, 2024

Beside crash the biggest issue here seems to be fact that patches created for snippets are applied to the compiled file. It creates a non-compiling code, by overriding parts of sources that should not be modified. I belive patches should be never produced for compiled snipets.

Compiler version

All Scala 3 versions

Minimized code

//> using options -rewrite -source:3.4-migration
import scala.compiletime.testing.typeCheckErrors

def foo(arg: Int): Unit = ???

@main def Test = {
  typeCheckErrors("Seq.empty[Int].foreach(foo.apply _)")
  typeCheckErrors("Seq.empty[Int].foreach(foo.apply _)")
}

Output (click arrow to expand)

patched file /Users/wmazur/projects/sandbox/test.scala]

  exception occurred while compiling List(/Users/wmazur/projects/sandbox/test.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: <no file>
        during phase: parser
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.14
    compiler version: version 3.6.0-RC1-bin-20240821-a2c53a1-NIGHTLY-git-a2c53a1
            settings: -bootclasspath /Users/wmazur/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.6.0-RC1-bin-20240821-a2c53a1-NIGHTLY/scala3-library_3-3.6.0-RC1-bin-20240821-a2c53a1-NIGHTLY.jar:/Users/wmazur/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar -classpath /Users/wmazur/projects/sandbox/.scala-build/.bloop/sandbox_7573b3872e-92b0ef3e72/bloop-internal-classes/main-01uXd7V_QpCUQrX3EOBw2w==:/Users/wmazur/projects/sandbox/.scala-build/sandbox_7573b3872e-92b0ef3e72/classes/classes-empty-sandbox_7573b3872e-92b0ef3e72 -d /Users/wmazur/projects/sandbox/.scala-build/.bloop/sandbox_7573b3872e-92b0ef3e72/bloop-internal-classes/main-01uXd7V_QpCUQrX3EOBw2w== -java-output-version 17 -rewrite Some(dotty.tools.dotc.rewrites.Rewrites@66a109b1) -source 3.4-migration -sourceroot /Users/wmazur/projects/sandbox

Error compiling project (Scala 3.6.0-RC1-bin-20240821-a2c53a1-NIGHTLY, JVM (17))
Error: Unexpected error when compiling sandbox_7573b3872e-92b0ef3e72: java.lang.AssertionError: assertion failed: overlapping patches in /Users/wmazur/projects/sandbox/test.scala: Patch(<32..34>,) and Patch(<32..34>,)
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.rewrites.Rewrites$Patches.apply$$anonfun$1(Rewrites.scala:45)
        at scala.collection.IterableOnceOps.reduceLeft(IterableOnce.scala:861)
        at scala.collection.IterableOnceOps.reduceLeft$(IterableOnce.scala:851)
        at scala.collection.AbstractIterable.reduceLeft(Iterable.scala:935)
        at dotty.tools.dotc.rewrites.Rewrites$Patches.apply(Rewrites.scala:44)
        at dotty.tools.dotc.rewrites.Rewrites$Patches.writeBack(Rewrites.scala:70)
        at dotty.tools.dotc.rewrites.Rewrites$.writeBack$$anonfun$1$$anonfun$1(Rewrites.scala:101)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:619)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:617)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:935)
        at dotty.tools.dotc.rewrites.Rewrites$.writeBack$$anonfun$1(Rewrites.scala:99)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.Option.foreach(Option.scala:437)
        at dotty.tools.dotc.rewrites.Rewrites$.writeBack(Rewrites.scala:99)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:389)
        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.bloop.internal.BloopHighLevelCompiler.compileSources$1(BloopHighLevelCompiler.scala:133)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$7(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$1(BloopHighLevelCompiler.scala:71)
        at bloop.tracing.NoopTracer$.trace(BraveTracer.scala:53)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:70)
        at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$6(BloopHighLevelCompiler.scala:159)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at monix.eval.internal.TaskRunLoop$.startFull(TaskRunLoop.scala:81)
        at monix.eval.internal.TaskRestartCallback.syncOnSuccess(TaskRestartCallback.scala:101)
        at monix.eval.internal.TaskRestartCallback.onSuccess(TaskRestartCallback.scala:74)
        at monix.eval.internal.TaskExecuteOn$AsyncRegister$$anon$1.run(TaskExecuteOn.scala:71)
        at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Compilation failed
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.

2 participants