scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

Compiler crash when importing coursierapi `StringUtil` #20405

Closed counter2015 closed 2 months ago

counter2015 commented 4 months ago

Compiler version

Scala 3.4.2, JVM (17)

Minimized code

$ cat debug.scala
//> using scala 3.4.2
//> using dep "org.scalameta:scalafmt-dynamic_2.13:3.8.1"

import coursierapi.shaded.coursier.util.shaded.org.jsoup.internal.StringUtil

def debug() =
  println(StringUtil.isBlank(" "))

$ scala-cli compile debug.scala

Output (click arrow to expand)

```scala Compiling project (Scala 3.4.2, JVM (17)) assertion failure for coursierapi.shaded.coursier.type <:< ?{ util: ? }, frozen = false exception occurred while typechecking /home/counter/bugs/debug.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 -Yno-enrich-error-messages. while compiling: /home/counter/bugs/debug.scala during phase: typer mode: Mode(ImplicitsEnabled) library version: version 2.13.12 compiler version: version 3.4.2 settings: -bootclasspath /home/counter/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.4.2/scala3-library_3-3.4.2.jar:/home/counter/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar -classpath /home/counter/bugs/.scala-build/.bloop/bugs_e58a2a357d-18a71eca43/bloop-internal-classes/main--z08XYbDQjKmsNN65H7bMQ==:/home/counter/bugs/.scala-build/bugs_e58a2a357d-18a71eca43/classes/classes-empty-bugs_e58a2a357d-18a71eca43:/home/counter/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalafmt-dynamic_2.13/3.8.1/scalafmt-dynamic_2.13-3.8.1.jar:/home/counter/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalafmt-interfaces/3.8.1/scalafmt-interfaces-3.8.1.jar:/home/counter/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/interface/0.0.17/interface-0.0.17.jar:/home/counter/.cache/coursier/v1/https/repo1.maven.org/maven2/com/typesafe/config/1.4.3/config-1.4.3.jar -d /home/counter/bugs/.scala-build/.bloop/bugs_e58a2a357d-18a71eca43/bloop-internal-classes/main--z08XYbDQjKmsNN65H7bMQ== -java-output-version 17 -sourceroot /home/counter/bugs Error compiling project (Scala 3.4.2, JVM (17)) Error: Unexpected error when compiling bugs_e58a2a357d-18a71eca43: java.lang.AssertionError: assertion failed: coursierapi.shaded.coursier.package$. already has a symbol at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) at dotty.tools.dotc.core.SymbolLoaders$.enterNew(SymbolLoaders.scala:44) at dotty.tools.dotc.core.SymbolLoaders$.enterClass(SymbolLoaders.scala:55) at dotty.tools.dotc.core.SymbolLoaders$.enterClassAndModule(SymbolLoaders.scala:106) at dotty.tools.dotc.core.classfile.ClassfileParser.enterClassAndModule$1(ClassfileParser.scala:1066) at dotty.tools.dotc.core.classfile.ClassfileParser.enterOwnInnerClasses$$anonfun$1(ClassfileParser.scala:1074) 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:576) at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:574) at dotty.tools.dotc.util.GenericHashMap$EntryIterator.foreach(GenericHashMap.scala:177) at dotty.tools.dotc.core.classfile.ClassfileParser.enterOwnInnerClasses(ClassfileParser.scala:1074) at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:399) at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:302) at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:297) at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:415) at dotty.tools.dotc.core.SymbolLoader$$anon$1.doComplete(SymbolLoaders.scala:330) at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:346) at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:178) at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190) at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMembersNamed(SymDenotations.scala:2160) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2130) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamedNoShadowingBasedOnFlags(SymDenotations.scala:2153) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.nonPrivateMembersNamed(SymDenotations.scala:2143) at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.recur$5(SymDenotations.scala:2512) at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.computeMembersNamed(SymDenotations.scala:2579) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2130) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2181) at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:756) at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:937) at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:729) at dotty.tools.dotc.core.Types$Type.member(Types.scala:713) at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:207) at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:2185) at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:345) at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1553) at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:214) at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:224) at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:132) at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:149) at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:3199) at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:4093) at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4180) at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4407) at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3701) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:775) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:817) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3112) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:775) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:817) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3112) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:775) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:817) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3112) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:775) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:817) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3112) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:775) at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:817) at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3112) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1690) at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1680) at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1690) at dotty.tools.dotc.typer.Namer$Completer.$anonfun$15(Namer.scala:811) at dotty.tools.dotc.typer.Typer.typedImportQualifier(Typer.scala:2915) at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:811) at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:955) at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:831) at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:178) at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190) at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192) at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:398) at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3084) at dotty.tools.dotc.typer.Typer.typedImport(Typer.scala:2918) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3150) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3314) at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370) at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2947) at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3171) at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298) at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302) at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413) at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47) 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.monitor(Phases.scala:477) at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53) at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99) at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479) at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583) at scala.collection.immutable.List.prependedAll(List.scala:152) at scala.collection.immutable.List$.from(List.scala:684) at scala.collection.immutable.List$.from(List.scala:681) at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898) at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:100) at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315) 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:337) at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350) at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360) at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69) at dotty.tools.dotc.Run.compileUnits(Run.scala:360) at dotty.tools.dotc.Run.compileSources(Run.scala:261) at dotty.tools.dotc.Run.compile(Run.scala:246) 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 ```
Gedochao commented 4 months ago

We'll need to minimize this to an example without the external dependency. @counter2015 would you be able to help?

counter2015 commented 4 months ago

I'm not sure where is the root cause. But I have tried on 2.13.14, it has same problem.

He-Pin commented 4 months ago

copy the method body?

counter2015 commented 4 months ago

After coping import coursierapi.shaded.coursier.util.shaded.org.jsoup.internal.StringUtil and coursierapi.shaded.coursier.util.shaded.org.jsoup.helper.Validate to java source of the project directory without the external dependency , the code compiles.

It seems not only method body which makes compiler crashed.

He-Pin commented 4 months ago

That maybe related jar reading

Gedochao commented 4 months ago

That maybe related jar reading

It might, although the crash happens somewhere in the typer... 🤔

lrytz commented 4 months ago

The error message from Scala 2 (which also crashes) is maybe more useful

No RuntimeVisibleAnnotations in classfile with ScalaSignature attribute: package object coursier

It's a broken assumption in the classfile. Maybe there's something special in the build of the referenced dependencies (i see shaded).