@@ -298,19 +298,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
298
298
}
299
299
}
300
300
301
- /** In capture checking, implements the logic to compare type variables which represent
302
- * capture variables.
303
- *
304
- * Note: should only be called in a context where tp1 or tp2 is a type variable representing a capture variable.
305
- *
306
- * @return -1 if tp1 or tp2 is not a capture variables, 1 if both tp1 and tp2 are capture variables and tp1 is a subcapture of tp2,
307
- * 0 if both tp1 and tp2 are capture variables but tp1 is not a subcapture of tp2.
308
- */
309
- inline def tryHandleCaptureVars : Int =
310
- if ! (isCaptureCheckingOrSetup && tp1.derivesFrom(defn.Caps_CapSet ) && tp1.derivesFrom(defn.Caps_CapSet )) then - 1
311
- else if (subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK) then 1
312
- else 0
313
-
314
301
def firstTry : Boolean = tp2 match {
315
302
case tp2 : NamedType =>
316
303
def compareNamed (tp1 : Type , tp2 : NamedType ): Boolean =
@@ -359,9 +346,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
359
346
&& isSubPrefix(tp1.prefix, tp2.prefix)
360
347
&& tp1.signature == tp2.signature
361
348
&& ! (sym1.isClass && sym2.isClass) // class types don't subtype each other
362
- || {val cv = tryHandleCaptureVars
363
- if (cv < 0 ) then thirdTryNamed(tp2)
364
- else cv != 0 }
349
+ || thirdTryNamed(tp2)
365
350
case _ =>
366
351
secondTry
367
352
end compareNamed
@@ -449,14 +434,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
449
434
450
435
def secondTry : Boolean = tp1 match {
451
436
case tp1 : NamedType =>
452
- val cv = tryHandleCaptureVars
453
- if (cv >= 0 ) then return cv != 0
454
437
tp1.info match {
455
438
case info1 : TypeAlias =>
456
439
if (recur(info1.alias, tp2)) return true
457
440
if (tp1.prefix.isStable) return tryLiftedToThis1
458
441
case _ =>
459
- if (tp1 eq NothingType ) || isBottom(tp1) then return true
442
+ if isCaptureVarComparison then
443
+ return subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK
444
+ if (tp1 eq NothingType ) || isBottom(tp1) then
445
+ return true
460
446
}
461
447
thirdTry
462
448
case tp1 : TypeParamRef =>
@@ -604,6 +590,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
604
590
|| narrowGADTBounds(tp2, tp1, approx, isUpper = false ))
605
591
&& (isBottom(tp1) || GADTusage (tp2.symbol))
606
592
593
+ if isCaptureVarComparison then
594
+ return subCaptures(tp1.captureSet, tp2.captureSet, frozenConstraint).isOK
595
+
607
596
isSubApproxHi(tp1, info2.lo) && (trustBounds || isSubApproxHi(tp1, info2.hi))
608
597
|| compareGADT
609
598
|| tryLiftedToThis2
@@ -878,9 +867,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
878
867
def compareCapturing : Boolean =
879
868
val refs1 = tp1.captureSet
880
869
try
881
- if tp1.isInstanceOf [TypeRef ] then
882
- val cv = tryHandleCaptureVars
883
- if (cv >= 0 ) then return (cv != 0 )
884
870
if refs1.isAlwaysEmpty then recur(tp1, parent2)
885
871
else
886
872
// The singletonOK branch is because we sometimes have a larger capture set in a singleton
@@ -1600,6 +1586,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1600
1586
(tp2a ne tp2) && recur(tp1, tp2a) && { opaquesUsed = true ; true }
1601
1587
}
1602
1588
1589
+ def isCaptureVarComparison : Boolean =
1590
+ isCaptureCheckingOrSetup
1591
+ && tp1.derivesFrom(defn.Caps_CapSet )
1592
+ && tp2.derivesFrom(defn.Caps_CapSet )
1593
+
1603
1594
// begin recur
1604
1595
if tp2 eq NoType then false
1605
1596
else if tp1 eq tp2 then true
0 commit comments