Skip to content

Crash for generation of higher-kinded mirror #9088

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

Closed
odersky opened this issue May 31, 2020 · 0 comments
Closed

Crash for generation of higher-kinded mirror #9088

odersky opened this issue May 31, 2020 · 0 comments

Comments

@odersky
Copy link
Contributor

odersky commented May 31, 2020

Minimized code

This is a version of the test tests/run/poly-kinded-derives.scala where all type parameters are made explicit. The critical change is in the the line marked // <<<<

import scala.deriving._

object Test extends App {
  {
    trait Show[T]
    object Show {
      given Show[Int] {}
      given [T](using st: Show[T]) as Show[Tuple1[T]]
      given t2[T, U](using st: Show[T], su: Show[U]) as Show[(T, U)]
      given t3 [T, U, V](using st: Show[T], su: Show[U], sv: Show[V]) as Show[(T, U, V)]

      def derived[T](using m: Mirror.Of[T], r: Show[m.MirroredElemTypes]): Show[T] = new Show[T] {}
    }

    case class Mono(i: Int) derives Show
    case class Poly[A](a: A) derives Show
    //case class Poly11[F[_]](fi: F[Int]) derives Show
    case class Poly2[A, B](a: A, b: B) derives Show
    case class Poly3[A, B, C](a: A, b: B, c: C) derives Show
  }

  {
    trait Functor[F[_]]
    object Functor {
      given [C] as Functor[[T] =>> C] {}
      given Functor[[T] =>> Tuple1[T]] {}
      given t2 [T] as Functor[[U] =>> (T, U)] {}
      given t3 [T, U] as Functor[[V] =>> (T, U, V)] {}

      def derived[F[_]](using m: Mirror { type MirroredType[X] = F[X] ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]): Functor[F] = new Functor[F] {}
    }

    case class Mono(i: Int) derives Functor
    case class Poly[A](a: A) derives Functor
    //case class Poly11[F[_]](fi: F[Int]) derives Functor
    case class Poly2[A, B](a: A, b: B) derives Functor
    case class Poly3[A, B, C](a: A, b: B, c: C) derives Functor
  }

  {
    trait FunctorK[F[_[_]]]
    object FunctorK {
      given [C] as FunctorK[[F[_]] =>> C] {}
      given [T] as FunctorK[[F[_]] =>> Tuple1[F[T]]]

      def derived[F[_[_]]](using m: Mirror { type MirroredType[X[_]] = F[X] ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]): FunctorK[F] = new FunctorK[F] {} // <<<<
    }

    case class Mono(i: Int) derives FunctorK
    //case class Poly[A](a: A) derives FunctorK
    case class Poly11[F[_]](fi: F[Int]) derives FunctorK
    //case class Poly2[A, B](a: A, b: B) derives FunctorK
    //case class Poly3[A, B, C](a: A, b: B, c: C) derives FunctorK
  }

  {
    trait Bifunctor[F[_, _]]
    object Bifunctor {
      given [C] as Bifunctor[[T, U] =>> C] {}
      given Bifunctor[[T, U] =>> Tuple1[U]] {}
      given t2 as Bifunctor[[T, U] =>> (T, U)] {}
      given t3 [T] as Bifunctor[[U, V] =>> (T, U, V)] {}

      def derived[F[_, _]](using m: Mirror { type MirroredType[X, Y] = F[X, Y] ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]): Bifunctor[F] = ???
    }

    case class Mono(i: Int) derives Bifunctor
    case class Poly[A](a: A) derives Bifunctor
    //case class Poly11[F[_]](fi: F[Int]) derives Bifunctor
    case class Poly2[A, B](a: A, b: B) derives Bifunctor
    case class Poly3[A, B, C](a: A, b: B, c: C) derives Bifunctor
  }
}

Output

We get a crash in productMirror:

exception occurred while typechecking ../run/poly-kinded-derives.scala
exception occurred while compiling ../run/poly-kinded-derives.scala
java.lang.AssertionError: assertion failed: invalid prefix HKTypeLambda(List(X), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))), AppliedType(TypeVar(TypeParamRef(F)),List(TypeParamRef(X)))) while compiling ../run/poly-kinded-derives.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: invalid prefix HKTypeLambda(List(X), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))), AppliedType(TypeVar(TypeParamRef(F)),List(TypeParamRef(X))))
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.core.Types$NamedType.<init>(Types.scala:1870)
	at dotty.tools.dotc.core.Types$TypeRef.<init>(Types.scala:2426)
	at dotty.tools.dotc.core.Types$CachedTypeRef.<init>(Types.scala:2482)
	at dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:64)
	at dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:68)
	at dotty.tools.dotc.core.Types$TypeRef$.apply(Types.scala:2538)
	at dotty.tools.dotc.core.Types$NamedType$.apply(Types.scala:2514)
	at dotty.tools.dotc.core.Types$NamedType.withPrefix(Types.scala:2361)
	at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2294)
	at dotty.tools.dotc.core.Types$TypeMap.derivedSelect(Types.scala:4873)
	at dotty.tools.dotc.core.Types$ApproximatingTypeMap.derivedSelect(Types.scala:5165)
	at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.op$1(TypeOps.scala:102)
	at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:110)
	at dotty.tools.dotc.core.TypeOps$.asSeenFrom(TypeOps.scala:55)
	at dotty.tools.dotc.core.Types$Type.asSeenFrom(Types.scala:901)
	at dotty.tools.dotc.core.Types$Type.memberInfo(Types.scala:893)
	at dotty.tools.dotc.typer.Synthesizer.$anonfun$3(Synthesizer.scala:282)
	at scala.collection.immutable.List.map(List.scala:223)
	at dotty.tools.dotc.typer.Synthesizer.productMirror(Synthesizer.scala:282)

Expectation

Should compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants