Skip to content

[Scala3] Move OpaqueTypeSpec and DirectionSpec#5399

Open
adkian-sifive wants to merge 1 commit into
mainfrom
adkian-sifive/scala3-opaquetypespec
Open

[Scala3] Move OpaqueTypeSpec and DirectionSpec#5399
adkian-sifive wants to merge 1 commit into
mainfrom
adkian-sifive/scala3-opaquetypespec

Conversation

@adkian-sifive
Copy link
Copy Markdown
Member

@adkian-sifive adkian-sifive commented May 29, 2026

OpaqueTypeSpec is is causing a compiler crash on trait MaybeBoxed

java.lang.AssertionError: assertion failed: 'new' call to non-constructor: $init$
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:783)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:385)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:303)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:297)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadQualifier(BCodeBodyBuilder.scala:1191)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genTypeApply(BCodeBodyBuilder.scala:694)
	at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:483)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:899)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:922)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:697)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:705)
	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.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:705)
	at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:293)
	at dotty.tools.backend.jvm.CodeGen.genClass(CodeGen.scala:156)
	at dotty.tools.backend.jvm.CodeGen.genClassDef$1(CodeGen.scala:61)
	at dotty.tools.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:117)
	at dotty.tools.backend.jvm.CodeGen.genClassDefs$1$$anonfun$1(CodeGen.scala:115)
	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.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:115)
	at dotty.tools.backend.jvm.CodeGen.genClassDefs$1$$anonfun$1(CodeGen.scala:115)
	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.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:115)
	at dotty.tools.backend.jvm.CodeGen.genUnit(CodeGen.scala:120)
	at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:83)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:341)
	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.core.Phases$Phase.runOn(Phases.scala:337)
	at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:91)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:351)
	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:344)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:393)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:393)
	at dotty.tools.dotc.Run.compileSources(Run.scala:297)
	at dotty.tools.dotc.Run.compile(Run.scala:282)
	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.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:196)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:252)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:186)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:166)
	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:241)
	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:166)
	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:214)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:542)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:542)
	at sbt.internal.inc.Incremental$.$anonfun$apply$3(Incremental.scala:182)
	at sbt.internal.inc.Incremental$.$anonfun$apply$3$adapted(Incremental.scala:180)
	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:458)
	at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:264)
	at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:413)
	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:500)
	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:400)
	at sbt.internal.inc.Incremental$.apply(Incremental.scala:208)
	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:542)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:496)
	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:433)
	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
	at mill.javalib.zinc.ZincWorker.compileInternal(ZincWorker.scala:506)
	at mill.javalib.zinc.ZincWorker.compileMixed$$anonfun$1(ZincWorker.scala:228)
	at mill.javalib.zinc.ZincWorker.withScalaCompilers$$anonfun$2(ZincWorker.scala:331)
	at mill.util.CachedFactoryWithInitData.withValue(CachedFactory.scala:54)
	at mill.javalib.zinc.ZincWorker.withScalaCompilers(ZincWorker.scala:330)
	at mill.javalib.zinc.ZincWorker.compileMixed(ZincWorker.scala:216)
	at mill.javalib.zinc.ZincWorker$$anon$4.compileMixed(ZincWorker.scala:303)
	at mill.javalib.worker.JvmWorkerImpl.$anonfun$5(JvmWorkerImpl.scala:71)
	at mill.util.Timed$.apply(Timed.scala:14)
	at mill.javalib.worker.JvmWorkerImpl.compileMixed(JvmWorkerImpl.scala:71)
	at mill.scalalib.ScalaModule.compile$$anonfun$1$$anonfun$1(ScalaModule.scala:273)
	at mill.api.Task$Named.evaluate(Task.scala:338)
	at mill.api.Task$Named.evaluate$(Task.scala:323)
	at mill.api.Task$Computed.evaluate(Task.scala:349)
	at mill.exec.GroupExecution.$anonfun$14(GroupExecution.scala:332)
	at mill.exec.GroupExecution$.wrap$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(GroupExecution.scala:641)
	at mill.api.daemon.ClassLoader$.withContextClassLoader(ClassLoader.scala:14)
	at mill.exec.GroupExecution$.wrap$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(GroupExecution.scala:648)
	at mill.api.Evaluator$.withCurrentEvaluator$$anonfun$2$$anonfun$1(Evaluator.scala:151)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.Evaluator$.withCurrentEvaluator$$anonfun$2(Evaluator.scala:152)
	at scala.util.Using$.resource(Using.scala:296)
	at mill.api.Evaluator$.withCurrentEvaluator(Evaluator.scala:153)
	at mill.exec.GroupExecution$.wrap$$anonfun$1$$anonfun$1$$anonfun$1(GroupExecution.scala:649)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:49)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:50)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:51)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:52)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at scala.Console$.withErr(Console.scala:193)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:53)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at scala.Console$.withOut(Console.scala:164)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:54)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at scala.Console$.withIn(Console.scala:227)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1(SystemStreamsUtils.scala:55)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams(SystemStreamsUtils.scala:56)
	at mill.exec.GroupExecution$.wrap$$anonfun$1$$anonfun$1(GroupExecution.scala:650)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.exec.GroupExecution$.wrap$$anonfun$1(GroupExecution.scala:651)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.exec.GroupExecution$.wrap(GroupExecution.scala:652)
	at mill.exec.GroupExecution.executeGroup$$anonfun$1(GroupExecution.scala:345)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.Vector.foreach(Vector.scala:2125)
	at mill.exec.GroupExecution.executeGroup(GroupExecution.scala:292)
	at mill.exec.GroupExecution.executeGroupCached(GroupExecution.scala:208)
	at mill.exec.GroupExecution.executeGroupCached$(GroupExecution.scala:20)
	at mill.exec.Execution.executeGroupCached(Execution.scala:16)
	at mill.exec.Execution.evaluateTerminals$1$$anonfun$1$$anonfun$1$$anonfun$1(Execution.scala:228)
	at mill.api.daemon.Logger.withPromptLine(Logger.scala:40)
	at mill.api.daemon.Logger.withPromptLine$(Logger.scala:12)
	at mill.internal.PrefixLogger.withPromptLine(PrefixLogger.scala:21)
	at mill.exec.Execution.evaluateTerminals$1$$anonfun$1$$anonfun$1(Execution.scala:260)
	at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
	at mill.exec.ExecutionContexts$.execute$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(ExecutionContexts.scala:67)
	at mill.exec.ExecutionContexts$.execute$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$adapted$1(ExecutionContexts.scala:68)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:49)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:50)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:51)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:52)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at scala.Console$.withErr(Console.scala:193)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:53)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at scala.Console$.withOut(Console.scala:164)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1$$anonfun$1(SystemStreamsUtils.scala:54)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at scala.Console$.withIn(Console.scala:227)
	at mill.api.SystemStreamsUtils$.withStreams$$anonfun$1(SystemStreamsUtils.scala:55)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.api.SystemStreamsUtils$.withStreams(SystemStreamsUtils.scala:56)
	at mill.exec.ExecutionContexts$.execute$$anonfun$1$$anonfun$1$$anonfun$1(ExecutionContexts.scala:68)
	at mill.exec.ExecutionContexts$.execute$$anonfun$1$$anonfun$1$$anonfun$adapted$1(ExecutionContexts.scala:69)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.exec.ExecutionContexts$.execute$$anonfun$1$$anonfun$1(ExecutionContexts.scala:69)
	at mill.exec.ExecutionContexts$.execute$$anonfun$1$$anonfun$adapted$1(ExecutionContexts.scala:70)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at mill.exec.ExecutionContexts$.mill$exec$ExecutionContexts$ThreadPool$$_$execute$$anonfun$1(ExecutionContexts.scala:70)
	at mill.exec.ExecutionContexts$ThreadPool$PriorityRunnable.run(ExecutionContexts.scala:89)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
[error] Error while emitting chisel3/src/test/scala/chiselTests/experimental/OpaqueTypeSpec.scala
[error] assertion failed: 'new' call to non-constructor: $init$

Summary

OpaqueTypeSpec was hitting two errors in Scala 3:

class MaybeBoxed needs to be abstract, since:
it has 3 unimplemented members.
  // Members declared in chiselTests.experimental.OpaqueTypeSpec$.MaybeBoxed
  def boxed: Boolean = ???
  def underlying: T = ???
  
  // Members declared in chisel3.Record
  def elements: scala.collection.immutable.SeqMap[String, chisel3.Data] = ???

and

def underlying = elements.head._2
                 ^^^^^^^^^^^^^^^^
          Found:    chisel3.Data
          Required: T
          where:    T is a type in class Boxed with bounds <: chisel3.Data

Release Notes

OpaqueTypeSpec now supported in Scala 3

@adkian-sifive adkian-sifive added the Scala 3 Changes related to upgrading to Scala 3 label May 29, 2026
@adkian-sifive adkian-sifive enabled auto-merge (squash) June 1, 2026 05:59
Comment thread src/test/scala/chiselTests/experimental/OpaqueTypeSpec.scala
Comment on lines 117 to 119
lazy val elements = SeqMap("underlying" -> gen)
def underlying = elements.head._2
def underlying = elements.head._2.asInstanceOf[T]
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this code doesn't matter that much, users often look at the tests for examples and this is not the right way to fix this.

What is happening, is that in Scala 2.13, the type of lazy val elements infers to be SeqMap[String, T] (the more specific type), while Scala 3 keeps the type as SeqMap[String, Data]. More to the spirit of the original test would be to add that type annotation and thus remove the need for the cast.

Better yet than that though would be to change this to just:

val underlying = gen
lazy val elements = SeqMap("underlying" -> underlying)

@adkian-sifive adkian-sifive changed the title [Scala3] Move OpaqueTypeSpec and DirectionSpec [Scala3] Move OpaqueTypeSpec Jun 3, 2026
@adkian-sifive adkian-sifive changed the title [Scala3] Move OpaqueTypeSpec [Scala3] Move OpaqueTypeSpec and DirectionSpec Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scala 3 Changes related to upgrading to Scala 3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants