@@ -106,8 +106,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
106106 * to the corresponding class parameters, which does not constitute
107107 * a true usage of a GADT symbol.
108108 */
109- private def GADTusage (sym : Symbol ) = {
110- if (! sym.owner.isConstructor) GADTused = true
109+ private def GADTusage (sym : Symbol ): true = recordGadtUsageIf(! sym.owner.isConstructor)
110+
111+ private def recordGadtUsageIf (cond : Boolean ): true = {
112+ if cond then
113+ GADTused = true
111114 true
112115 }
113116
@@ -512,7 +515,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
512515
513516 case tp1 : MatchType =>
514517 val reduced = tp1.reduced
515- if (reduced.exists) recur(reduced, tp2) else thirdTry
518+ if reduced.exists then
519+ recur(reduced, tp2) && recordGadtUsageIf { MatchType .thatReducesUsingGadt(tp1) }
520+ else thirdTry
516521 case _ : FlexType =>
517522 true
518523 case _ =>
@@ -712,7 +717,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
712717 either(recur(tp1, tp21), recur(tp1, tp22)) || fourthTry
713718 case tp2 : MatchType =>
714719 val reduced = tp2.reduced
715- if (reduced.exists) recur(tp1, reduced) else fourthTry
720+ if reduced.exists then
721+ recur(tp1, reduced) && recordGadtUsageIf { MatchType .thatReducesUsingGadt(tp2) }
722+ else
723+ fourthTry
716724 case tp2 : MethodType =>
717725 def compareMethod = tp1 match {
718726 case tp1 : MethodType =>
@@ -779,7 +787,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
779787 && (! caseLambda.exists || canWidenAbstract || tp1.widen.underlyingClassRef(refinementOK = true ).exists)
780788 then
781789 isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow)
782- && { GADTused ||= MatchType .thatReducesUsingGadt(tp1); true }
790+ && recordGadtUsageIf { MatchType .thatReducesUsingGadt(tp1) }
783791 || base.isInstanceOf [OrType ] && fourthTry
784792 // if base is a disjunction, this might have come from a tp1 type that
785793 // expands to a match type. In this case, we should try to reduce the type
@@ -1141,8 +1149,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
11411149 isSubArgs(args1, args2, tp1, tparams)
11421150 }
11431151 }
1144- if (res && touchedGADTs) GADTused = true
1145- res
1152+ res && recordGadtUsageIf(touchedGADTs)
11461153 case _ =>
11471154 false
11481155 }
@@ -1201,7 +1208,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
12011208 */
12021209 def compareLower (tycon2bounds : TypeBounds , tyconIsTypeRef : Boolean ): Boolean =
12031210 if ((tycon2bounds.lo `eq` tycon2bounds.hi) && ! tycon2bounds.isInstanceOf [MatchAlias ])
1204- if (tyconIsTypeRef) recur(tp1, tp2.superTypeNormalized)
1211+ if (tyconIsTypeRef) recur(tp1, tp2.superTypeNormalized) && recordGadtUsageIf( MatchType .thatReducesUsingGadt(tp2))
12051212 else isSubApproxHi(tp1, tycon2bounds.lo.applyIfParameterized(args2))
12061213 else
12071214 fallback(tycon2bounds.lo)
@@ -1215,7 +1222,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
12151222 inFrozenGadt { compareLower(bounds2, tyconIsTypeRef = false ) }
12161223 }
12171224 case _ => false
1218- } && { GADTused = true ; true }
1225+ } && recordGadtUsageIf( true )
12191226
12201227 tycon2 match {
12211228 case param2 : TypeParamRef =>
@@ -1268,14 +1275,14 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
12681275 def byGadtBounds : Boolean =
12691276 sym.onGadtBounds { bounds1 =>
12701277 inFrozenGadt { isSubType(bounds1.hi.applyIfParameterized(args1), tp2, approx.addLow) }
1271- } && { GADTused = true ; true }
1278+ } && recordGadtUsageIf( true )
12721279
12731280
12741281 ! sym.isClass && {
12751282 defn.isCompiletimeAppliedType(sym) && compareCompiletimeAppliedType(tp1, tp2, fromBelow = false ) ||
1276- recur(tp1.superTypeNormalized, tp2) ||
1283+ { recur(tp1.superTypeNormalized, tp2) && recordGadtUsageIf( MatchType .thatReducesUsingGadt(tp1)) } ||
12771284 tryLiftedToThis1
1278- }|| byGadtBounds
1285+ } || byGadtBounds
12791286 case tycon1 : TypeProxy =>
12801287 recur(tp1.superTypeNormalized, tp2)
12811288 case _ =>
0 commit comments