Scala 3.5.0 - Compilation issue when using Spire 3 0.18

I’m compiling with all the Spire dependencies as per its own POM file.

These are my compiler options:

-language:strictEquality
-Yexplicit-nulls
-Yno-flexible-types
-Wsafe-init
-explain
-indent
-new-syntax
-Xfatal-warnings
-Wunused:all
-Wvalue-discard
-Wnonunit-statement
-Xcheck-macros
-source future
-Ydebug-unpickling

The following code:

import spire.math.UInt

class TestingCode:
  def testFunction(value: UInt): Unit = ???
  val tc = TestingCode().testFunction(1)

Gives:

Could not read definition value UIntAlgebra in C:\path\spire_3-0.18.0.jar(spire/math/UIntInstances.tasty). Caused by the following exception:
dotty.tools.dotc.core.UnpicklingError: Could not read definition type SignedAdditiveCMonoid in C:\path\spire_3-0.18.0.jar(spire/algebra/package.tasty). Caused by the following exception:
java.lang.AssertionError: assertion failed: module class Signed$ has non-class parent: AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class cats)),object kernel),OrderFunctions),List(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object algebra),package),Order)))
    scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.traverse$1(SymDenotations.scala:2007)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeBaseData(SymDenotations.scala:2012)
    dotty.tools.dotc.core.SymDenotations$BaseDataImpl.apply(SymDenotations.scala:3001)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseData(SymDenotations.scala:1978)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseClassSet(SymDenotations.scala:1994)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.derivesFrom(SymDenotations.scala:2020)
    dotty.tools.dotc.core.Types$Type.loop$1(Types.scala:278)
    dotty.tools.dotc.core.Types$Type.derivesFrom(Types.scala:302)
    dotty.tools.dotc.typer.Checking$CheckNonCyclicMap.isInteresting$1(Checking.scala:335)
    dotty.tools.dotc.typer.Checking$CheckNonCyclicMap.apply(Checking.scala:351)
    dotty.tools.dotc.typer.Checking$CheckNonCyclicMap.apply(Checking.scala:316)
    dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:6230)
    dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6261)
    dotty.tools.dotc.typer.Checking$CheckNonCyclicMap.apply(Checking.scala:376)
    dotty.tools.dotc.typer.Checking$CheckNonCyclicMap.checkPart(Checking.scala:272)
    dotty.tools.dotc.typer.Checking$CheckNonCyclicMap.checkInfo(Checking.scala:290)
    dotty.tools.dotc.typer.Checking$.checkNonCyclic(Checking.scala:407)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readNewDef(TreeUnpickler.scala:967)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedDef(TreeUnpickler.scala:866)
    dotty.tools.dotc.core.tasty.TreeUnpickler$Completer.complete(TreeUnpickler.scala:166)
    dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
    dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
    dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
    dotty.tools.dotc.core.SymDenotations$LazyType.completerTypeParams(SymDenotations.scala:2767)
    dotty.tools.dotc.core.TypeApplications$.typeParams$extension(TypeApplications.scala:186)
    dotty.tools.dotc.core.TypeApplications$.appliedTo$extension(TypeApplications.scala:373)
    dotty.tools.dotc.core.TypeApplications$.safeAppliedTo$extension(TypeApplications.scala:455)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1540)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1623)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.$anonfun$41(TreeUnpickler.scala:1538)
    dotty.tools.tasty.TastyReader.until(TastyReader.scala:135)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1538)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1623)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.$anonfun$41(TreeUnpickler.scala:1538)
    dotty.tools.tasty.TastyReader.until(TastyReader.scala:135)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1538)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1623)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.$anonfun$41(TreeUnpickler.scala:1538)
    dotty.tools.tasty.TastyReader.until(TastyReader.scala:135)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1538)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1623)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.$anonfun$41(TreeUnpickler.scala:1538)
    dotty.tools.tasty.TastyReader.until(TastyReader.scala:135)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTree$1(TreeUnpickler.scala:1538)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTree(TreeUnpickler.scala:1598)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1623)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readNewDef(TreeUnpickler.scala:934)
    dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedDef(TreeUnpickler.scala:866)
    dotty.tools.dotc.core.tasty.TreeUnpickler$Completer.complete(TreeUnpickler.scala:166)
    dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
    dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
    dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
    dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1130)
    dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1083)
    dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:137)
    dotty.tools.dotc.core.Denotations$SingleDenotation.mapInherited(Denotations.scala:1065)
    dotty.tools.dotc.core.Denotations$SingleDenotation.mapInherited(Denotations.scala:1062)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.collect$1(SymDenotations.scala:2174)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.collect$1(SymDenotations.scala:2170)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.addInherited(SymDenotations.scala:2179)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMembersNamed(SymDenotations.scala:2164)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2131)
    dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2182)
    dotty.tools.dotc.core.Types$Type.go$1(Types.scala:778)
    dotty.tools.dotc.core.Types$Type.findMember(Types.scala:959)
    dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:751)
    dotty.tools.dotc.core.Types$Type.member(Types.scala:735)
    dotty.tools.dotc.core.Types$Type.implicitMembersNamed(Types.scala:758)
    dotty.tools.dotc.core.Types$Type.implicitMembers$$anonfun$1(Types.scala:1073)
    scala.runtime.function.JProcedure2.apply(JProcedure2.java:15)
    scala.runtime.function.JProcedure2.apply(JProcedure2.java:10)
    dotty.tools.dotc.core.Types$.dotty$tools$dotc$core$Types$Type$$_$memberDenots$$anonfun$1(Types.scala:1005)
    scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    scala.collection.immutable.Set$Set3.foreach(Set.scala:261)
    dotty.tools.dotc.core.Types$Type.memberDenots(Types.scala:1005)
    dotty.tools.dotc.core.Types$Type.implicitMembers(Types.scala:1073)
    dotty.tools.dotc.typer.Implicits$OfTypeImplicits.refs$$anonfun$1(Implicits.scala:277)
    dotty.tools.dotc.typer.TermRefSet.handle$1(Implicits.scala:2161)
    dotty.tools.dotc.typer.TermRefSet.foreach$$anonfun$1(Implicits.scala:2163)
    java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:986)
    dotty.tools.dotc.typer.TermRefSet.foreach(Implicits.scala:2163)
    dotty.tools.dotc.typer.Implicits$OfTypeImplicits.refs(Implicits.scala:277)
    dotty.tools.dotc.typer.Implicits$OfTypeImplicits.eligible(Implicits.scala:284)
    dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1689)
    dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit$$anonfun$2(Implicits.scala:1773)
    dotty.tools.dotc.typer.Implicits$SearchResult.recoverWith(Implicits.scala:430)
    dotty.tools.dotc.typer.Implicits$ImplicitSearch.searchImplicit(Implicits.scala:1759)
    dotty.tools.dotc.typer.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1800)
    dotty.tools.dotc.typer.Implicits.inferImplicit(Implicits.scala:1109)
    dotty.tools.dotc.typer.Implicits.inferImplicit$(Implicits.scala:860)
    dotty.tools.dotc.typer.Typer.inferImplicit(Typer.scala:145)
    dotty.tools.dotc.typer.Implicits.inferView(Implicits.scala:900)
    dotty.tools.dotc.typer.Implicits.inferView$(Implicits.scala:860)
    dotty.tools.dotc.typer.Typer.inferView(Typer.scala:145)
    dotty.tools.dotc.typer.Typer.adaptToSubType$1(Typer.scala:4529)
    dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:4350)
    dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:4430)
    dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4660)
    dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3932)
    dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:514)
    dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:996)
    dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:996)
    dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:688)
    dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:752)
    dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:574)
    dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:878)
    dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:995)
    dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1257)
    dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:434)
    dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:145)
    dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:1068)
    dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1178)
    dotty.tools.dotc.typer.Typer$.tryEither(Typer.scala:118)
    dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1193)
    dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1231)
    dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:434)
    dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:145)
    dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3392)
    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3477)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
    dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3669)
    dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1747)
    dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1737)
    dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1747)
    dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:2073)
    dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
    dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:2073)
    dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:2081)
    dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:2100)
    dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:2101)
    dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:2112)
    dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1779)
    dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1785)
    dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:823)
    dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:974)
    dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:850)
    dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
    dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
    dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
    dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
    dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3339)
    dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3364)
    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3476)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
    dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3580)
    dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3626)
    dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3074)
    dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3380)
    dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3384)
    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3476)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
    dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3580)
    dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3626)
    dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3207)
    dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3426)
    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3477)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
    dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3607)
    dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3626)
    dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3207)
    dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3426)
    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3477)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
    dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
    dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3669)
    dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
    scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:503)
    dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
    dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
    scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
    scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
    scala.collection.immutable.List.prependedAll(List.scala:155)
    scala.collection.immutable.List$.from(List.scala:685)
    scala.collection.immutable.List$.from(List.scala:682)
    scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
    dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:98)
    dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
    scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
    dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
    dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
    dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
    dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
    dotty.tools.dotc.Run.compileUnits(Run.scala:396)
    dotty.tools.dotc.Run.compileSources(Run.scala:282)
    dotty.tools.dotc.Run.compile(Run.scala:267)
    dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
    dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
    dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
    sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
    org.jetbrains.jps.incremental.scala.local.IdeaIncrementalCompiler.compile(IdeaIncrementalCompiler.scala:47)
    org.jetbrains.jps.incremental.scala.local.LocalServer.doCompile(LocalServer.scala:50)
    org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:28)
    org.jetbrains.jps.incremental.scala.remote.Main$.compileLogic(Main.scala:210)
    org.jetbrains.jps.incremental.scala.remote.Main$.$anonfun$handleCommand$1(Main.scala:193)
    org.jetbrains.jps.incremental.scala.remote.Main$.decorated$1(Main.scala:180)
    org.jetbrains.jps.incremental.scala.remote.Main$.handleCommand(Main.scala:190)
    org.jetbrains.jps.incremental.scala.remote.Main$.serverLogic(Main.scala:163)
    org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:103)
    org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
    java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    java.base/java.lang.reflect.Method.invoke(Method.java:580)
    com.facebook.nailgun.NGSession.runImpl(NGSession.java:312)
    com.facebook.nailgun.NGSession.run(NGSession.java:198)
  val tc = TestingCode().testFunction(1)

As you can see from the trace I’m using Intellij IDEA, on Windows.

If you think I should report it to JetBrains or the Spire maintainers, sorry for the noise, and please let me know, unfortunately I can’t say by myself if that’s the case or not.

The only thing that I’m sure of is that with the same Spire binaries, but previous versions of Scala and IDEA, this wasn’t happening.

Maybe there’s something wrong with the InteliJ driver. It worked fine for me when using scala directly. Maybe there’s something wrong with the classpath? The compiler crashes when trying to convert Int to UInt, AFAIK there is no implicit conversion defined for it. In normal compilation, it would just fail with Type Mismatch Error.

Here’s working scala / scala-cli reproducer. Changing ui"1" to just 1 would lead to compilation error.

//> using dep "org.typelevel::spire:0.18.0"
//> using options -language:strictEquality -Yexplicit-nulls -Yno-flexible-types 
//> using options -Wsafe-init -explain -indent  -new-syntax -Xfatal-warnings -Wunused:all -Wvalue-discard -Wnonunit-statement
//> using options -Xcheck-macros -source:future -Ydebug-unpickling 

import spire.math.UInt
import spire.implicits.*

class TestingCode:
  def testFunction(value: UInt): Unit = ???
  val tc = TestingCode().testFunction(ui"1")

Thanks @WojciechMazur, after all it wasn’t even an IntelliJ issue.

It was entirely my fault for missing the dependency on cats-kernel.
I insist on retrieving my dependencies manually.
This isn’t the first time I’ve been bit by this but hopefully it will be the last, starting now I’m using SBT to make sure that I’m getting everything that’s needed.

Thanks again for pointing me in the right direction.

1 Like