zio / izumi-reflect

TypeTag without scala-reflect. Supports Scala 2 and Scala 3.
https://zio.dev/izumi-reflect
Other
141 stars 37 forks source link

Tag generation fails for Scala Array #474

Open improved-broccoli opened 3 months ago

improved-broccoli commented 3 months ago

Scala version: 3.4.2 Izumi reflect version: 2.3.8 (transitively from zio-mock)

Writing a ZIO Mock using the Scala Array type makes the compiler crash with:

Compiler output ``` java.lang.AssertionError: assertion failed: class Array at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) at dotty.tools.backend.jvm.BCodeHelpers.primitiveOrClassToBType$1(BCodeHelpers.scala:717) at dotty.tools.backend.jvm.BCodeHelpers.dotty$tools$backend$jvm$BCodeHelpers$$typeToTypeKind(BCodeHelpers.scala:737) at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.toTypeKind(BCodeHelpers.scala:202) at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.toTypeKind$(BCodeHelpers.scala:130) at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.toTypeKind(BCodeSkelBuilder.scala:134) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genConstant(BCodeBodyBuilder.scala:582) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:451) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:304) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.loop$1(BCodeBodyBuilder.scala:1210) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadArguments(BCodeBodyBuilder.scala:1217) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:836) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:386) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:466) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:304) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:321) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:304) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genStat(BCodeBodyBuilder.scala:116) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlockTo$$anonfun$1(BCodeBodyBuilder.scala:1094) 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.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlockTo(BCodeBodyBuilder.scala:1094) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:458) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:304) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.loop$1(BCodeBodyBuilder.scala:1210) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadArguments(BCodeBodyBuilder.scala:1217) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:836) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:386) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:304) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genStat(BCodeBodyBuilder.scala:116) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlockTo$$anonfun$1(BCodeBodyBuilder.scala:1094) 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.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlockTo(BCodeBodyBuilder.scala:1094) at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:458) at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:893) at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:916) at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:693) at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:699) 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.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:699) at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:293) at dotty.tools.backend.jvm.CodeGen.genClass(CodeGen.scala:154) at dotty.tools.backend.jvm.CodeGen.genClassDef$1(CodeGen.scala:62) 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:333) 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:354) 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.Phases$Phase.runOn(Phases.scala:360) at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:91) 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.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183) at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180) at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178) at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464) 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:263) at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419) at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506) at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406) at sbt.internal.inc.Incremental$.apply(Incremental.scala:172) at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534) at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488) at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425) at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371) at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321) at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31) ```

The error comes from the makeTag Macro. Here is a demo: https://scastie.scala-lang.org/ugTtSPC9STqinqMGS1nieQ

pshirshov commented 2 months ago

I have a strong feeling that we've already reported that as a bug in dotty. UPD: can't find it, could you report it there?..

jdegoes commented 2 weeks ago

/bounty $250

algora-pbc[bot] commented 2 weeks ago

💎 $250 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #474 with your implementation plan
  2. Submit work: Create a pull request including /claim #474 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/izumi-reflect!

Add a bountyShare on socials

pshirshov commented 2 weeks ago

@jdegoes I've reported the issue to the compiler team, this is up to them to resolve. So, I think the bounty should be removed from this issue.

som-snytt commented 2 weeks ago

or, the bounty should be doubled if the fix is upstream! because a. the solution is harder and b. it is more valuable because it benefits more people. plus c. if the compiler team doesn't need to supply the fix, they are free to pursue other work.

pshirshov commented 2 weeks ago

Anyway, the bounty shouldn't be here, this issue cannot be solved on i-r level, this is a bug in the compiler.

jchyb commented 5 days ago

Looks like the Array type parameter is lost somewhere before that Array type is applied to the classOf method in the macro.