-
Notifications
You must be signed in to change notification settings - Fork 1.1k
crash for -Wsafe-init with munit and munit-scalacheck #22442
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
Comments
As a note, the new munit-scalacheck release does indeed make the specific issue go away. However, I still think the (in my experience) high rate of compiler crashes for -Wsafe-init makes this feature hard to recommend, even though I quite like the added safety net :/ |
I did some initial investigation. The stacktrace contains By printing more information from the checker, we can see the error happens with java.lang.Exception:
fun tpe = <error wrong number of arguments at pickleQuotes for (message: String, clues: munit.Clues, loc: munit.Location): Nothing: (ScalaCheckSuite.this.fail :
(message: String, clues: munit.Clues, loc: munit.Location): Nothing), expected: 3, found: 2>,
tree = ScalaCheckSuite.this.fail("\n".+(renderResult(result)),
ScalaCheckSuite.this.fail$default$2)(test.location) /cc: @olhotak |
The difference between the two versions of The method The problem is that the code below should not even type check: Try(fail("\n" + renderResult(result))(test.location)) Because there is no version of With implicit val loc = test.location
Try(fail("\n" + renderResult(result))) And after type checking, we get the following tree, which the initialization checker can handle without problem: ScalaCheckSuite.this.fail("\n".+(renderResult(result)),
ScalaCheckSuite.this.fail$default$2)(loc, munit.diff.DiffOptions.default) I'd suggest minimizing this as a bug for the typer. |
This looks like a binary compatibility issue.
|
Good point, so the versions are binary compatible but not tasty compatible: The code However, in the particular run they mix |
I guess we should add https://github.com/scalacenter/tasty-mima for the future. We can't really do too much now as it's published. Sorry about the issue and thanks @liufengyun for figuring it out! |
A question remains whether More generally, what should be the behaviour of the compiler when it is provided two libraries that are Tasty-incompatible? |
The compiler does emit an error message before crashing. The crash comes only after the following error message output:
A possible fix for the crash would be for the initialization checker to ignore (with a warning) any trees whose construction from Tasty emitted errors. |
This PR would fix the error raised in #22442. The error arises when reading incompatible TASTy trees. This PR checks if an error occurs when fetching the rhs of ValOrDefDef trees and gives a warning.
my best guess is this is related to munit-scalacheck being compiled with an older scala version, as copy&pasting the ScalaCheckSuite does not exhibit the error.
Still would be nice if something systematic could be done to prevent this kind of crash with safe-init
Compiler version
tested: 3.6.2, 3.6.3, 3.5.2, 3.7.0-RC1-bin-20250122-b709262-NIGHTLY
Minimized code
https://scastie.scala-lang.org/BLCh6nVwRyumizn6wi27LA
Output (click arrow to expand)
Error: Unexpected error when compiling Slips_d8c005c033-test: scala.MatchError: dotty.tools.dotc.core.Types$PreviousErrorType@7911d345 (of class dotty.tools.dotc.core.Types$PreviousErrorType)
at dotty.tools.dotc.transform.init.Util$Call$.unapply(Util.scala:45)
at dotty.tools.dotc.transform.init.Util$NewExpr$.unapply(Util.scala:65)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1224)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$30(Semantic.scala:1005)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.stopEarly(Semantic.scala:433)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1002)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$38(Semantic.scala:1160)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1159)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$8(Semantic.scala:635)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.errorsIn(Semantic.scala:425)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$7(Semantic.scala:635)
at scala.collection.immutable.List.flatMap(List.scala:294)
at dotty.tools.dotc.transform.init.Semantic$.checkArgsWithParametricity$1(Semantic.scala:634)
at dotty.tools.dotc.transform.init.Semantic$.call(Semantic.scala:673)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$44(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1330)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$2(Semantic.scala:1189)
at scala.collection.immutable.List.map(List.scala:251)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1189)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1344)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1330)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$10(Semantic.scala:718)
at dotty.tools.dotc.transform.init.Semantic$.call(Semantic.scala:717)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$44(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1330)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$2(Semantic.scala:1189)
at scala.collection.immutable.List.map(List.scala:247)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1189)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1344)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$30(Semantic.scala:1005)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.stopEarly(Semantic.scala:433)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1002)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$38(Semantic.scala:1160)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1159)
at dotty.tools.dotc.transform.init.Semantic$.promoteArgs$1$$anonfun$1(Semantic.scala:617)
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.transform.init.Semantic$.promoteArgs$1(Semantic.scala:617)
at dotty.tools.dotc.transform.init.Semantic$.call(Semantic.scala:682)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$44(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$30(Semantic.scala:1005)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.stopEarly(Semantic.scala:433)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1002)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$38(Semantic.scala:1160)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1159)
at dotty.tools.dotc.transform.init.Semantic$.promoteArgs$1$$anonfun$1(Semantic.scala:617)
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.transform.init.Semantic$.promoteArgs$1(Semantic.scala:617)
at dotty.tools.dotc.transform.init.Semantic$.call(Semantic.scala:682)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$44(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1262)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1330)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$30(Semantic.scala:1005)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.stopEarly(Semantic.scala:433)
at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:1002)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$5(Semantic.scala:475)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$.dotty$tools$dotc$transform$init$Semantic$Reporter$$$$$$anonfun$3(Semantic.scala:440)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.stopEarly(Semantic.scala:433)
at dotty.tools.dotc.transform.init.Semantic$Reporter$.hasErrors(Semantic.scala:440)
at dotty.tools.dotc.transform.init.Semantic$.widenArg(Semantic.scala:475)
at dotty.tools.dotc.transform.init.Semantic$.widenArgs$$anonfun$1(Semantic.scala:489)
at scala.collection.immutable.List.map(List.scala:251)
at scala.collection.immutable.List.map(List.scala:79)
at dotty.tools.dotc.transform.init.Semantic$.widenArgs(Semantic.scala:489)
at dotty.tools.dotc.transform.init.Semantic$.instantiate(Semantic.scala:864)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$40(Semantic.scala:1231)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1229)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.init$$anonfun$4(Semantic.scala:1597)
at scala.collection.immutable.List.foreach(List.scala:334)
at dotty.tools.dotc.transform.init.Semantic$.init(Semantic.scala:1595)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1393)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$17(Semantic.scala:796)
at dotty.tools.dotc.transform.init.Semantic$.callConstructor(Semantic.scala:796)
at dotty.tools.dotc.transform.init.Semantic$.superCall$1$$anonfun$1(Semantic.scala:1524)
at dotty.tools.dotc.transform.init.Semantic$.init$$anonfun$3(Semantic.scala:1589)
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.transform.init.Semantic$.init(Semantic.scala:1589)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1393)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:126)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.$anonfun$17(Semantic.scala:796)
at dotty.tools.dotc.transform.init.Semantic$.callConstructor(Semantic.scala:796)
at dotty.tools.dotc.transform.init.Semantic$.superCall$1$$anonfun$1(Semantic.scala:1524)
at dotty.tools.dotc.transform.init.Semantic$.init$$anonfun$3(Semantic.scala:1589)
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.transform.init.Semantic$.init(Semantic.scala:1589)
at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1393)
at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Cache.cachedEval(Cache.scala:112)
at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1184)
at dotty.tools.dotc.transform.init.Semantic$.iterate$1(Semantic.scala:1133)
at dotty.tools.dotc.transform.init.Semantic$.checkClass(Semantic.scala:1144)
at dotty.tools.dotc.transform.init.Semantic$.checkClasses$$anonfun$2(Semantic.scala:1153)
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 scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:905)
at dotty.tools.dotc.transform.init.Semantic$.checkClasses(Semantic.scala:1152)
at dotty.tools.dotc.transform.init.Checker.runOn$$anonfun$1(Checker.scala:54)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at dotty.tools.dotc.core.Phases$Phase.cancellable(Phases.scala:528)
at dotty.tools.dotc.transform.init.Checker.runOn(Checker.scala:59)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:345)
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:338)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:385)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:397)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
at dotty.tools.dotc.Run.compileUnits(Run.scala:397)
at dotty.tools.dotc.Run.compileSources(Run.scala:284)
at dotty.tools.dotc.Run.compile(Run.scala:269)
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:148)
at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$9(BloopHighLevelCompiler.scala:181)
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:73)
at bloop.tracing.NoopTracer$.trace(BraveTracer.scala:53)
at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.timed$1(BloopHighLevelCompiler.scala:72)
at sbt.internal.inc.bloop.internal.BloopHighLevelCompiler.$anonfun$compile$8(BloopHighLevelCompiler.scala:181)
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.compute(ForkJoinTask.java:1726)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(ForkJoinTask.java:1717)
at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(ForkJoinTask.java:1641)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1458)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2034)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:189)
The text was updated successfully, but these errors were encountered: