Loading coursier-interfaces crashes the compiler
Closed this issue · 4 comments
dos65 commented
3.4.1
Minimized code
//> using scala 3
//> using dep "io.get-coursier:interface:1.0.19"
import coursierapi.shaded.coursier.internal.api.ApiHelper //<- this import leads to the issue
val foo = "asd"
Output (click arrow to expand)
exception caught when loading module class package$: java.lang.AssertionError: assertion failed: duplicate module class Dependency$#4218; previous was class Dependency$#4204
assertion failure for coursierapi.shaded.coursier.type <:< ?{ internal: ? }, frozen = false
java.lang.AssertionError: assertion failed: duplicate module class Dependency$#4218; previous was class Dependency$#4204 while typechecking /home/v.chelyshov/projects/oss/samples/scalabug-cs/bug.scala
exception occurred while typechecking /home/v.chelyshov/projects/oss/samples/scalabug-cs/bug.scala
exception occurred while compiling /home/v.chelyshov/projects/oss/samples/scalabug-cs/bug.scala
java.lang.AssertionError: assertion failed: duplicate module class Dependency$#4218; previous was class Dependency$#4204 while compiling /home/v.chelyshov/projects/oss/samples/scalabug-cs/bug.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: duplicate module class Dependency$#4218; previous was class Dependency$#4204
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.core.Scopes$MutableScope.enter(Scopes.scala:271)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.enterNoReplace(SymDenotations.scala:2035)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.enter(SymDenotations.scala:2026)
at dotty.tools.dotc.core.Symbols$Symbol.entered(Symbols.scala:207)
at dotty.tools.dotc.core.NamerOps$.addConstructorProxies$$anonfun$1(NamerOps.scala:170)
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:333)
at dotty.tools.dotc.core.Scopes$Scope.foreach(Scopes.scala:93)
at dotty.tools.dotc.core.NamerOps$.addConstructorProxies(NamerOps.scala:176)
at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:221)
at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:82)
at dotty.tools.dotc.core.ClassfileLoader.load(SymbolLoaders.scala:412)
at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:407)
at dotty.tools.dotc.core.SymbolLoader$$anon$1.doComplete(SymbolLoaders.scala:325)
at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:341)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMembersNamed(SymDenotations.scala:2113)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2083)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamedNoShadowingBasedOnFlags(SymDenotations.scala:2106)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.nonPrivateMembersNamed(SymDenotations.scala:2096)
at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.recur$5(SymDenotations.scala:2466)
at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.computeMembersNamed(SymDenotations.scala:2533)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2083)
at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2134)
at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:689)
at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:872)
at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:672)
at dotty.tools.dotc.core.Types$Type.member(Types.scala:656)
at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.liftedTree1$1(ProtoTypes.scala:204)
at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:226)
at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:2041)
at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:328)
at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1455)
at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:208)
at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:218)
at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:144)
at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:2938)
at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:3828)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3907)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4120)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3435)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:686)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:724)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2897)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:686)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:724)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2897)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1619)
at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1609)
at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1619)
at dotty.tools.dotc.typer.Namer$Completer.$anonfun$14(Namer.scala:790)
at dotty.tools.dotc.typer.Typer.typedImportQualifier(Typer.scala:2664)
at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:790)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:922)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:810)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:390)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2869)
at dotty.tools.dotc.typer.Typer.typedImport(Typer.scala:2667)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2940)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3074)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3130)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2692)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2961)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
at scala.Function0.apply$mcV$sp(Function0.scala:42)
at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:437)
at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
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:333)
at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:247)
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:1321)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:263)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:271)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:280)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:280)
at dotty.tools.dotc.Run.compileSources(Run.scala:195)
at dotty.tools.dotc.Run.compile(Run.scala:179)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
at dotty.tools.dotc.Driver.process(Driver.scala:195)
at dotty.tools.dotc.Driver.process(Driver.scala:163)
at dotty.tools.dotc.Driver.process(Driver.scala:175)
at dotty.tools.dotc.Driver.main(Driver.scala:205)
at dotty.tools.dotc.Main.main(Main.scala)
Compilation failed
Gedochao commented
We'll still need to minimise it to a snippet without the dependency.
mbovel commented
bracevac commented
Conclusions after the issue spree:
- The example should indeed fail. The underlying problem is that a Scala 2 classfile is loaded with its metadata stripped + it is not recommended to work directly with
shaded
packages and classes. - We're going implement a more descriptive error message in the class loader for Java/Scala2 classes (same message that the Scala 2 compiler gives).
- Issue #20405 has exactly the same problem.
- Since this is at the level of classfiles/class loading, it's tricky to add test cases (& we don't want tests that include external dependencies),