@@ -46,6 +46,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
4646 state = c.typerState
4747 monitored = false
4848 GADTused = false
49+ opaquesUsed = false
4950 recCount = 0
5051 needsGc = false
5152 if Config .checkTypeComparerReset then checkReset()
@@ -61,6 +62,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
6162 /** Indicates whether the subtype check used GADT bounds */
6263 private var GADTused : Boolean = false
6364
65+ /** Indicates whether the subtype check used opaque types */
66+ private var opaquesUsed : Boolean = false
67+
6468 private var myInstance : TypeComparer = this
6569 def currentInstance : TypeComparer = myInstance
6670
@@ -142,8 +146,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
142146
143147 def testSubType (tp1 : Type , tp2 : Type ): CompareResult =
144148 GADTused = false
149+ opaquesUsed = false
145150 if ! topLevelSubType(tp1, tp2) then CompareResult .Fail
146151 else if GADTused then CompareResult .OKwithGADTUsed
152+ else if opaquesUsed then CompareResult .OKwithOpaquesUsed // we cast on GADTused, so handles if both are used
147153 else CompareResult .OK
148154
149155 /** The current approximation state. See `ApproxState`. */
@@ -1483,12 +1489,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
14831489
14841490 def tryLiftedToThis1 : Boolean = {
14851491 val tp1a = liftToThis(tp1)
1486- (tp1a ne tp1) && recur(tp1a, tp2)
1492+ (tp1a ne tp1) && recur(tp1a, tp2) && { opaquesUsed = true ; true }
14871493 }
14881494
14891495 def tryLiftedToThis2 : Boolean = {
14901496 val tp2a = liftToThis(tp2)
1491- (tp2a ne tp2) && recur(tp1, tp2a)
1497+ (tp2a ne tp2) && recur(tp1, tp2a) && { opaquesUsed = true ; true }
14921498 }
14931499
14941500 // begin recur
@@ -2935,7 +2941,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
29352941object TypeComparer {
29362942
29372943 enum CompareResult :
2938- case OK , Fail , OKwithGADTUsed
2944+ case OK , Fail , OKwithGADTUsed , OKwithOpaquesUsed
29392945
29402946 /** Class for unification variables used in `natValue`. */
29412947 private class AnyConstantType extends UncachedGroundType with ValueType {
0 commit comments