Skip to content

Regression in erasure for typelevel/spotted-leopards #23616

@WojciechMazur

Description

@WojciechMazur

Based on OpenCB failure in typelevel/spotted-leopards - build logs

Compiler version

Last good release: 3.7.3-RC1-bin-20250726-1148afe-NIGHTLY
First bad release: 3.7.3-RC1-bin-20250728-95b37a7-NIGHTLY
Bisect points to ef84d41 / #21890

Minimized code

trait Apply[F[_]]:
  extension [A](fa: F[A])
    def map[B](f: A => B): F[B]
    def map2[B, Z](fb: F[B])(f: (A, B) => Z): F[Z] = ???

  private case class IsMap[T <: Tuple](value: Tuple.Map[T, F])
  private inline def tupledGeneric[T <: Tuple](tuple: Tuple.Map[T, F]): F[T] = 
    inline IsMap(tuple) match
      case t: IsMap[h *: EmptyTuple] => t.value.head.map(_ *: EmptyTuple)
      case t: IsMap[h *: t] =>
        val head = t.value.head
        val tail = tupledGeneric(t.value.tail)
        head.map2(tail)(_ *: _)

trait Monad[F[_]] extends Apply[F]:
  extension [A](fa: F[A]) def flatMap[B](f: A => F[B]): F[B]
  extension [A](fa: F[A]) override def map[B](f: A => B): F[B] = ???

opaque type Kleisli[F[_], A, B] = A => F[B]
given [F[_], A](using F: Monad[F]): Monad[[B] =>> Kleisli[F, A, B]] with
  extension [B](k: Kleisli[F, A, B])
    def flatMap[C](f: B => Kleisli[F, A, C]) = ???

Output

  unhandled exception while running MegaPhase{elimErasedValueType, pureStats, vcElideAllocations, etaReduce, arrayApply, elimPolyFunction, tailrec, completeJavaEnums, mixin, lazyVals, memoize, nonLocalReturns, capturedVars} on /Users/wmazur/projects/scala/community-build3/example.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 -Xno-enrich-error-messages.


     while compiling: /Users/wmazur/projects/scala/community-build3/example.scala
        during phase: MegaPhase{elimErasedValueType, pureStats, vcElideAllocations, etaReduce, arrayApply, elimPolyFunction, tailrec, completeJavaEnums, mixin, lazyVals, memoize, nonLocalReturns, capturedVars}
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.16
    compiler version: version 3.7.3-RC1-bin-20250728-95b37a7-NIGHTLY-git-95b37a7
            settings: -classpath /Users/wmazur/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.7.3-RC1-bin-20250728-95b37a7-NIGHTLY/scala3-library_3-3.7.3-RC1-bin-20250728-95b37a7-NIGHTLY.jar:/Users/wmazur/.sdkman/candidates/scala/current/maven2/org/scala-lang/scala-library/2.13.16/scala-library-2.13.16.jar -d /Users/wmazur/projects/scala/community-build3/.scala-build/community-build3_8234e07519-990a7af3ef/classes/main -sourceroot /Users/wmazur/projects/scala/community-build3

Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.core.Types$MethodType.<init>(Types.scala:4160)
        at dotty.tools.dotc.core.Types$CachedMethodType.<init>(Types.scala:4183)
        at dotty.tools.dotc.core.Types$MethodTypeCompanion.apply(Types.scala:4263)
        at dotty.tools.dotc.core.Types$MethodTypeCompanion.apply(Types.scala:4262)
        at dotty.tools.dotc.core.Types$LambdaTypeCompanion.apply(Types.scala:4195)
        at dotty.tools.dotc.core.TypeErasure.eraseInfo(TypeErasure.scala:823)
        at dotty.tools.dotc.core.TypeErasure$.transformInfo(TypeErasure.scala:277)
        at dotty.tools.dotc.transform.Mixin.mkMixinForwarderSym$1(Mixin.scala:334)
        at dotty.tools.dotc.transform.Mixin.mixinForwarders$1$$anonfun$2(Mixin.scala:318)
        at scala.collection.Iterator$$anon$9.next(Iterator.scala:584)
        at scala.collection.immutable.List.prependedAll(List.scala:156)
        at scala.collection.immutable.List$.from(List.scala:685)
        at scala.collection.immutable.List$.from(List.scala:682)
        at scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
        at dotty.tools.dotc.transform.Mixin.mixinForwarders$1(Mixin.scala:315)
        at dotty.tools.dotc.transform.Mixin.$anonfun$6(Mixin.scala:354)
        at scala.collection.immutable.List.flatMap(List.scala:294)
        at dotty.tools.dotc.transform.Mixin.transformTemplate(Mixin.scala:346)
        at dotty.tools.dotc.transform.Mixin.transformTemplate(Mixin.scala:196)
        at dotty.tools.dotc.transform.MegaPhase.goTemplate(MegaPhase.scala:1071)
        at dotty.tools.dotc.transform.MegaPhase.goTemplate(MegaPhase.scala:1072)
        at dotty.tools.dotc.transform.MegaPhase.goTemplate(MegaPhase.scala:1072)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:377)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:454)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:272)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:452)
        at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:465)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:465)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:376)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:454)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:272)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:452)
        at dotty.tools.dotc.transform.MegaPhase.loop$1(MegaPhase.scala:465)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:465)
        at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:396)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:399)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:454)
        at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:481)
        at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:493)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:386)
        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:379)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:368)
        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:361)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:408)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:408)
        at scala.Function0.apply$mcV$sp(Function0.scala:42)
        at dotty.tools.dotc.Run.showProgress(Run.scala:470)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:408)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:420)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:420)
        at dotty.tools.dotc.Run.compileSources(Run.scala:307)
        at dotty.tools.dotc.Run.compile(Run.scala:292)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:201)
        at dotty.tools.dotc.Driver.process(Driver.scala:169)
        at dotty.tools.dotc.Driver.process(Driver.scala:181)
        at dotty.tools.dotc.Driver.main(Driver.scala:211)
        at dotty.tools.dotc.Main.main(Main.scala)
Compilation failed

Expectation

Should compile

Metadata

Metadata

Assignees

Labels

itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions