Skip to content

Commit e7a6e31

Browse files
authored
Merge pull request #11910 from Linyxus/fix-gadt-hkt-ordering
Check GADT ordering for HKTs in TypeComparer
2 parents 23fb93f + cba7620 commit e7a6e31

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,16 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10451045
}
10461046
}
10471047

1048+
def byGadtOrdering: Boolean =
1049+
ctx.gadt.contains(tycon1sym)
1050+
&& ctx.gadt.contains(tycon2sym)
1051+
&& ctx.gadt.isLess(tycon1sym, tycon2sym)
1052+
10481053
val res = (
10491054
tycon1sym == tycon2sym && isSubPrefix(tycon1.prefix, tycon2.prefix)
10501055
|| byGadtBounds(tycon1sym, tycon2, fromAbove = true)
10511056
|| byGadtBounds(tycon2sym, tycon1, fromAbove = false)
1057+
|| byGadtOrdering
10521058
) && {
10531059
// There are two cases in which we can assume injectivity.
10541060
// First we check if either sym is a class.

tests/pos/gadt-hkt-ordering.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object test {
2+
final class HKTVar[+T[_]]
3+
4+
def foo[F[_], G[_], X](m : HKTVar[G]) = m match {
5+
case _ : HKTVar[F] =>
6+
val fx : F[X] = ???
7+
val gx : G[X] = fx
8+
}
9+
}

0 commit comments

Comments
 (0)