@@ -169,9 +169,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
169
169
private inline def inFrozenGadtAndConstraint [T ](inline op : T ): T =
170
170
inFrozenGadtIf(true )(inFrozenConstraint(op))
171
171
172
- extension (tp : TypeRef )
172
+ extension (sym : Symbol )
173
173
private inline def onGadtBounds (inline op : TypeBounds => Boolean ): Boolean =
174
- val bounds = gadtBounds(tp.symbol )
174
+ val bounds = gadtBounds(sym )
175
175
bounds != null && op(bounds)
176
176
177
177
protected def isSubType (tp1 : Type , tp2 : Type , a : ApproxState ): Boolean = {
@@ -490,11 +490,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
490
490
491
491
def thirdTryNamed (tp2 : NamedType ): Boolean = tp2.info match {
492
492
case info2 : TypeBounds =>
493
- def compareGADT : Boolean = {
494
- val gbounds2 = gadtBounds(tp2.symbol)
495
- (gbounds2 != null ) &&
496
- (isSubTypeWhenFrozen(tp1, gbounds2.lo) ||
497
- (tp1 match {
493
+ def compareGADT : Boolean =
494
+ tp2.symbol.onGadtBounds(gbounds2 =>
495
+ isSubTypeWhenFrozen(tp1, gbounds2.lo)
496
+ || tp1.match
498
497
case tp1 : NamedType if ctx.gadt.contains(tp1.symbol) =>
499
498
// Note: since we approximate constrained types only with their non-param bounds,
500
499
// we need to manually handle the case when we're comparing two constrained types,
@@ -503,10 +502,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
503
502
// comparing two constrained types, and that case will be handled here first.
504
503
ctx.gadt.isLess(tp1.symbol, tp2.symbol) && GADTusage (tp1.symbol) && GADTusage (tp2.symbol)
505
504
case _ => false
506
- }) ||
507
- narrowGADTBounds(tp2, tp1, approx, isUpper = false )) &&
508
- { isBottom(tp1) || GADTusage (tp2.symbol) }
509
- }
505
+ || narrowGADTBounds(tp2, tp1, approx, isUpper = false ))
506
+ && (isBottom(tp1) || GADTusage (tp2.symbol))
507
+
510
508
isSubApproxHi(tp1, info2.lo) || compareGADT || tryLiftedToThis2 || fourthTry
511
509
512
510
case _ =>
@@ -756,13 +754,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
756
754
case tp1 : TypeRef =>
757
755
tp1.info match {
758
756
case TypeBounds (_, hi1) =>
759
- def compareGADT = {
760
- val gbounds1 = gadtBounds(tp1.symbol)
761
- (gbounds1 != null ) &&
762
- (isSubTypeWhenFrozen(gbounds1.hi, tp2) ||
763
- narrowGADTBounds(tp1, tp2, approx, isUpper = true )) &&
764
- { tp2.isAny || GADTusage (tp1.symbol) }
765
- }
757
+ def compareGADT =
758
+ tp1.symbol.onGadtBounds(gbounds1 =>
759
+ isSubTypeWhenFrozen(gbounds1.hi, tp2)
760
+ || narrowGADTBounds(tp1, tp2, approx, isUpper = true ))
761
+ && (tp2.isAny || GADTusage (tp1.symbol))
762
+
766
763
isSubType(hi1, tp2, approx.addLow) || compareGADT || tryLiftedToThis1
767
764
case _ =>
768
765
def isNullable (tp : Type ): Boolean = tp.widenDealias match {
@@ -1038,17 +1035,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1038
1035
1039
1036
var touchedGADTs = false
1040
1037
var gadtIsInstantiated = false
1041
- def byGadtBounds (sym : Symbol , tp : Type , fromAbove : Boolean ): Boolean = {
1042
- touchedGADTs = true
1043
- val b = gadtBounds(sym)
1044
- def boundsDescr = if b == null then " null" else b.show
1045
- b != null && inFrozenGadt {
1046
- if fromAbove then isSubType(b.hi, tp) else isSubType(tp, b.lo)
1047
- } && {
1048
- gadtIsInstantiated = b.isInstanceOf [TypeAlias ]
1049
- true
1050
- }
1051
- }
1038
+
1039
+ extension (sym : Symbol )
1040
+ inline def byGadtBounds (inline op : TypeBounds => Boolean ): Boolean =
1041
+ touchedGADTs = true
1042
+ sym.onGadtBounds(
1043
+ b => op(b) && { gadtIsInstantiated = b.isInstanceOf [TypeAlias ]; true })
1052
1044
1053
1045
def byGadtOrdering : Boolean =
1054
1046
ctx.gadt.contains(tycon1sym)
@@ -1057,8 +1049,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1057
1049
1058
1050
val res = (
1059
1051
tycon1sym == tycon2sym && isSubPrefix(tycon1.prefix, tycon2.prefix)
1060
- || byGadtBounds(tycon1sym, tycon2, fromAbove = true )
1061
- || byGadtBounds(tycon2sym, tycon1, fromAbove = false )
1052
+ || tycon1sym. byGadtBounds(b => isSubTypeWhenFrozen(b.hi, tycon2) )
1053
+ || tycon2sym. byGadtBounds(b => isSubTypeWhenFrozen( tycon1, b.lo) )
1062
1054
|| byGadtOrdering
1063
1055
) && {
1064
1056
// There are two cases in which we can assume injectivity.
@@ -1712,7 +1704,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1712
1704
case tp : AndType => true
1713
1705
case OrType (tp1, tp2) => containsAnd(tp1) || containsAnd(tp2)
1714
1706
case tp : TypeParamRef => containsAnd(bounds(tp).hi)
1715
- case tp : TypeRef => containsAnd(tp.info.hiBound) || tp.onGadtBounds(gbounds => containsAnd(gbounds.hi))
1707
+ case tp : TypeRef => containsAnd(tp.info.hiBound) || tp.symbol. onGadtBounds(gbounds => containsAnd(gbounds.hi))
1716
1708
case tp : TypeProxy => containsAnd(tp.superType)
1717
1709
case _ => false
1718
1710
0 commit comments