@@ -298,34 +298,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
298
298
}
299
299
}
300
300
301
- // TODO move the following functions somewhere more appropriate
302
- /**
303
- * Is the type `tp` a `CapSet` type, i.e., a capture variable?
304
- *
305
- * @param tp The type to check
306
- * @param includeCapSet Whether to include the bare `CapSet` type itself in the check, false at the top level
307
- */
308
- def isCapSet (tp : Type , includeCapSet : Boolean = false ): Boolean = tp match {
309
- case tp : TypeRef => (includeCapSet && (tp.symbol eq defn.Caps_CapSet )) || {
310
- tp.underlying match
311
- case TypeBounds (lo, hi) => isCapSet(lo, true ) && isCapSet(hi, true )
312
- case TypeAlias (alias) => isCapSet(alias) // TODO: test cases involving type aliases
313
- case _ => false
314
- }
315
- case tp : SingletonType => isCapSet(tp.underlying)
316
- case CapturingType (parent, _) => isCapSet(parent, true )
317
- case _ => false
318
- }
319
-
320
- /**
321
- * Assumes that isCapSet(tp) is true.
322
- */
323
- def captureSet (tp : Type ): CaptureSet = tp match
324
- case CapturingType (_,c) => c
325
- case tp : TypeRef if tp.symbol eq defn.Caps_CapSet => CaptureSet .empty
326
- case tp : SingletonType => captureSet(tp.underlying)
327
- case tp : CaptureRef => CaptureSet (tp)
328
-
329
301
/** In capture checking, implements the logic to compare type variables which represent
330
302
* capture variables.
331
303
*
@@ -335,8 +307,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
335
307
* 0 if both tp1 and tp2 are capture variables but tp1 is not a subcapture of tp2.
336
308
*/
337
309
inline def tryHandleCaptureVars : Int =
338
- if ! (isCaptureCheckingOrSetup && isCapSet(tp1 ) && isCapSet(tp2 )) then - 1
339
- else if (captureSet (tp1).subCaptures(captureSet( tp2) , frozenConstraint).isOK) then 1
310
+ if ! (isCaptureCheckingOrSetup && tp1. isCapSet() && tp2. isCapSet()) then - 1
311
+ else if (subCaptures (tp1.captureSetOfCapSet, tp2.captureSetOfCapSet , frozenConstraint).isOK) then 1
340
312
else 0
341
313
342
314
def firstTry : Boolean = tp2 match {
@@ -389,7 +361,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
389
361
&& ! (sym1.isClass && sym2.isClass) // class types don't subtype each other
390
362
|| {val cv = tryHandleCaptureVars
391
363
if (cv < 0 ) then thirdTryNamed(tp2)
392
- else cv > 0 }
364
+ else cv != 0 }
393
365
case _ =>
394
366
secondTry
395
367
end compareNamed
@@ -477,6 +449,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
477
449
478
450
def secondTry : Boolean = tp1 match {
479
451
case tp1 : NamedType =>
452
+ val cv = tryHandleCaptureVars
453
+ if (cv >= 0 ) then return cv != 0
480
454
tp1.info match {
481
455
case info1 : TypeAlias =>
482
456
if (recur(info1.alias, tp2)) return true
0 commit comments