Skip to content

Commit e4edcea

Browse files
committed
Fix the injectivity issue
1 parent 23f2d75 commit e4edcea

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import StdNames.nme
99
import TypeOps.refineUsingParent
1010
import collection.mutable
1111
import util.Stats
12+
import scala.util.DynamicVariable
1213
import config.Config
1314
import config.Feature.migrateTo3
1415
import 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

Comments
 (0)