@@ -9,6 +9,7 @@ import StdNames.nme
99import TypeOps .refineUsingParent
1010import collection .mutable
1111import util .Stats
12+ import scala .util .DynamicVariable
1213import config .Config
1314import config .Feature .migrateTo3
1415import config .Printers .{constr , subtyping , gadts , matchTypes , noPrinter }
@@ -60,6 +61,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
6061 /** Indicates whether the subtype check used GADT bounds */
6162 private var GADTused : Boolean = false
6263
64+ /** Indicates whether we have touched HKT GADT bounds */
65+ private val touchedHKGADT : DynamicVariable [Boolean ] = new DynamicVariable (false )
66+
67+ private def HKGADTtouched [T ](body : => T ): T = touchedHKGADT.withValue(true ) { body }
68+
6369 private var myInstance : TypeComparer = this
6470 def currentInstance : TypeComparer = myInstance
6571
@@ -1092,6 +1098,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10921098 val tyconIsInjective =
10931099 (tycon1sym.isClass || tycon2sym.isClass)
10941100 && (! touchedGADTs || gadtIsInstantiated)
1101+ && ! touchedHKGADT.value
10951102
10961103 inFrozenGadtIf(! tyconIsInjective) {
10971104 if tycon1sym == tycon2sym && tycon1sym.isAliasType then
@@ -1173,7 +1180,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
11731180 case tycon2 : TypeRef =>
11741181 val tycon2sym = tycon2.symbol
11751182 tycon2sym.onGadtBounds { bounds2 =>
1176- compareLower(bounds2, tyconIsTypeRef = false )
1183+ HKGADTtouched { compareLower(bounds2, tyconIsTypeRef = false ) }
11771184 }
11781185 case _ => false
11791186 } && { GADTused = true ; true }
0 commit comments