Skip to content

Commit 8f2e6e1

Browse files
author
Aleksander Boruch-Gruszecki
committed
Fixx issue with GADTs using HKTs
1 parent 01fac53 commit 8f2e6e1

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,28 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
740740
isSubArgs(args1, args2, tp1, tparams)
741741
case tycon1: TypeRef =>
742742
tycon2.dealiasKeepRefiningAnnots match {
743-
case tycon2: TypeRef if tycon1.symbol == tycon2.symbol =>
743+
case tycon2: TypeRef =>
744+
val tycon1sym = tycon1.symbol
745+
val tycon2sym = tycon2.symbol
746+
747+
var touchedGADTs = false
748+
def gadtBoundsContain(sym: Symbol, tp: Type): Boolean = {
749+
touchedGADTs = true
750+
val b = gadtBounds(sym)
751+
b != null && inFrozenConstraint {
752+
(b.lo =:= tp) && (b.hi =:= tp)
753+
}
754+
}
755+
756+
val res = (
757+
tycon1sym == tycon2sym ||
758+
gadtBoundsContain(tycon1sym, tycon2) ||
759+
gadtBoundsContain(tycon2sym, tycon1)
760+
) &&
744761
isSubType(tycon1.prefix, tycon2.prefix) &&
745762
isSubArgs(args1, args2, tp1, tparams)
763+
if (res && touchedGADTs) GADTused = true
764+
res
746765
case _ =>
747766
false
748767
}

tests/gadt/EQK.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
object EQK {
2+
sealed trait EQ[A, B]
3+
final case class Refl[A]() extends EQ[A, A]
4+
5+
sealed trait EQK[F[_], G[_]]
6+
final case class ReflK[F[_]]() extends EQK[F, F]
7+
8+
def m0[F[_], G[_], A](fa: F[A], eqk: EQK[F, G]): G[A] =
9+
eqk match { case ReflK() => fa }
10+
11+
def m1[F[_], G[_], A](fa: F[A], eq: EQ[A, Int], eqk: EQK[F, G]): G[Int] =
12+
eqk match {
13+
case ReflK() => eq match {
14+
case Refl() =>
15+
val r1: F[Int] = fa
16+
val r2: G[A] = fa
17+
val r3: F[Int] = r2
18+
fa : G[Int]
19+
}
20+
}
21+
22+
def m2[F[_], G[_], A](fa: F[A], a: A, eq: EQ[F[A], G[Int]], eqk: EQK[F, G]): Int =
23+
eqk match {
24+
case ReflK() => eq match {
25+
case Refl() =>
26+
val r1: F[Int] = fa
27+
val r2: G[A] = fa
28+
val r3: F[Int] = r2
29+
a
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)