Skip to content

Commit b696380

Browse files
committed
Check GADT ordering for HKTs
1 parent d527710 commit b696380

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,18 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10451045
}
10461046
}
10471047

1048+
var usedGadtOrdering: Boolean = false
1049+
def byGadtOrdering: Boolean =
1050+
ctx.gadt.contains(tycon1sym)
1051+
&& ctx.gadt.contains(tycon2sym)
1052+
&& ctx.gadt.isLess(tycon1sym, tycon2sym)
1053+
&& { usedGadtOrdering = true; true }
1054+
10481055
val res = (
10491056
tycon1sym == tycon2sym && isSubPrefix(tycon1.prefix, tycon2.prefix)
10501057
|| byGadtBounds(tycon1sym, tycon2, fromAbove = true)
10511058
|| byGadtBounds(tycon2sym, tycon1, fromAbove = false)
1059+
|| byGadtOrdering
10521060
) && {
10531061
// There are two cases in which we can assume injectivity.
10541062
// First we check if either sym is a class.
@@ -1058,9 +1066,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10581066
// 2) if we touched GADTs, then the _other_ symbol (class syms
10591067
// cannot have GADT constraints), the one w/ GADT cstrs,
10601068
// must be instantiated, making the two tycons equal
1069+
// 3) if we used GADT ordering, which means that neither symbol
1070+
// has been instantiated, we should not assume injectivity
10611071
val tyconIsInjective =
10621072
(tycon1sym.isClass || tycon2sym.isClass)
1063-
&& (!touchedGADTs || gadtIsInstantiated)
1073+
&& (!touchedGADTs || gadtIsInstantiated && !usedGadtOrdering)
10641074

10651075
inFrozenGadtIf(!tyconIsInjective) {
10661076
if tycon1sym == tycon2sym && tycon1sym.isAliasType then

0 commit comments

Comments
 (0)