-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assertion failed: <notype> class dotty.tools.dotc.ast.Trees$TypeTree -1 in ReTyper #13406
Comments
@joroKr21 could you try to minimize it without a reference to an external repository? |
That's unlikely - the project has a very similar |
@prolativ this is a regression from 3.0.1 |
Reduced to the following self-contained example. Further minimization may be possible. foo.scala // This file must be compiled with Scala 2.13
case class Foo[A](x: A) derived.scala import scala.compiletime.summonFrom
opaque type Derived[A] = A
object Derived:
def apply[A](instance: A): Derived[A] = instance
extension [A](derived: Derived[A]) def instance: A = derived
opaque type Or[A] = A
object Or extends OrInstances:
def apply[A](instance: A): Or[A] = instance
extension [A](or: Or[A]) def unify: A = or
sealed abstract class OrInstances:
inline given [A]: Derived.Or[A] = summonFrom {
case instance: A => Derived.Or(instance)
case derived: Derived[A] => Derived.Or(derived.instance)
} reducible.scala import scala.compiletime._
trait Reducible[F[_]]
object Reducible:
given Reducible[Foo] = ???
type DerivedReducible[F[_]] = Derived[Reducible[F]]
object DerivedReducible:
type Or[F[_]] = Derived.Or[Reducible[F]]
inline def apply[F[_]]: Reducible[F] =
import DerivedReducible.given
summonInline[DerivedReducible[F]].instance
def product[F[_]](ev: Reducible[?]): DerivedReducible[F] = ???
inline given [F[_]](using gen: K1.ProductGeneric[F]): DerivedReducible[F] =
product(K1.summonFirst[Or, gen.MirroredElemTypes, Const[Any]].unify)
given [F[_]](using inst: => K1.CoproductInstances[Or, F]): DerivedReducible[F] = ???
extension (F: Reducible.type)
inline def derived[F[_]]: Reducible[F] = DerivedReducible[F]
case class Bar[A](v: A)
case class FooAndBar[A](foo: Foo[A], bar: Bar[A])
object Test:
inline given [F[_]]: Reducible[F] = DerivedReducible[F]
summon[Reducible[FooAndBar]]
// all code below is extracted from shapeless3-deriving
import scala.deriving.Mirror
type Const[c] = [t] =>> c
object K1 {
type Kind[C, O[_]] = C {
type Kind = K1.type
type MirroredType[X] = O[X]
type MirroredMonoType = O[Any]
type MirroredElemTypes[_] <: Tuple
}
type ProductGeneric[O[_]] = Kind[Mirror.Product, O]
type CoproductGeneric[O[_]] = Kind[Mirror.Sum, O]
type CoproductInstances[F[_[_]], T[_]] = ErasedCoproductInstances[K1.type, F[T]]
type Head[T <: [X] =>> Any, A] = T[A] match { case h *: t => h }
type Tail[T <: [X] =>> Any, A] = T[A] match { case h *: t => t }
type LiftP[F[_[_]], T <: [X] =>> Any] <: Tuple =
T[Any] match {
case _ *: _ => F[[X] =>> Head[T, X]] *: LiftP[F, [X] =>> Tail[T, X]]
case _ => EmptyTuple
}
inline def summonFirst[F[_[_]], T[_], U[_]]: F[U] = summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]
transparent inline def summonFirst0[T]: Any = inline erasedValue[T] match {
case _: (a *: b) => summonFrom {
case aa: `a` => aa
case _ => summonFirst0[b]
}
}
}
final class ErasedCoproductInstances[K, FT](mirror: Mirror.Sum, is0: => Array[Any])
object ErasedCoproductInstances {
inline def apply[K, FT, E <: Tuple](mirror: Mirror.Sum) : ErasedCoproductInstances[K, FT] =
new ErasedCoproductInstances[K, FT](mirror, summonAsArray[E])
}
inline def summonAsArray[T <: Tuple]: Array[Any] =
summonAsArray0[T](0, new Array[Any](constValue[Tuple.Size[T]]))
inline def summonAsArray0[T](i: Int, arr: Array[Any]): Array[Any] = inline erasedValue[T] match {
case _: EmptyTuple => arr
case _: (a *: b) =>
arr(i) = summonInline[a]
summonAsArray0[b](i+1, arr)
} Compilation Output
|
The example in the above comment regressed in #12428 Also confirmed that reverting #12428 on release-3.0.2 fixes the original reproducer from typelevel/kittens#376 |
Minimized to // This file must be compiled with Scala 2.13
case class Foo[A](x: A) trait Bar
inline given derivedReducible(using scala.deriving.Mirror.ProductOf[Foo[_]]): Bar =
scala.compiletime.summonInline[Bar]
???
def test = derivedReducible |
Here is a backup of the |
We can replace |
It happens when retyping the empty constructor of an anonymous mirror (which is generated for Scala 2 classes): I'm not familiar with inlining to be able to tell what's going on with retyping. |
here is another example which does not need scala 2: // Qux_1.scala
sealed trait Qux[T] // anonymous mirror because no companion
object QuxImpl:
case class Foo[A](a: A) extends Qux[A] // Test_2.scala
trait Bar
// given Bar = ???
inline given derivedReducible(using scala.deriving.Mirror.SumOf[Qux[_]]): Bar =
scala.compiletime.summonInline[Bar]
???
def test = derivedReducible |
A workaround would be if I could somehow avoid a recursive |
What is the solution currently if I run into this error when using a third-party library? Is it to make sure every type I derive for has a companion object? |
That or revert to Scala 3.0.1 |
I'm not sure that this is the same problem, but I have the same assertion failure in Scala 3.1.1, again in the context of retyping an anonymous mirror, based on what I can see from the stacktrace. This was also observed when using Magnolia...
Minimised reproduction here: import magnolia1.{AutoDerivation, CaseClass, Monadic, SealedTrait}
trait SomeType[X] {}
object SomeType extends AutoDerivation[SomeType] {
// NOTE: the implementations have been left out, as they are irrelevant from
// the point of view of provoking the assertion failure.
def join[X](caseClass: CaseClass[Typeclass, X]): Typeclass[X] = ???
given SomeType[Int] = ???
def split[X](
sealedTrait: SealedTrait[Typeclass, X]
): Typeclass[X] = ???
}
object ProvokeCompilerAssertionFailure {
val okWithNonRecursiveX = implicitly[SomeType[Option[Int]]]
val troubleWithRecursiveX = implicitly[SomeType[List[Int]]]
} If this turns out to be a different bug, let me know and I'll raise a new issue. |
Compiler version
3.0.2-RC2
Minimized code
Reproducer: typelevel/kittens#376
The issue is in
ReducibleSuite
.Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: