@@ -481,6 +481,16 @@ class CheckCaptures extends Recheck, SymTransformer:
481
481
if sym.isConstructor then
482
482
val cls = sym.owner.asClass
483
483
484
+ /** Check if the class or one of its parents has a root capability,
485
+ * which means that the class has a capability annotation or an impure
486
+ * function type.
487
+ */
488
+ def hasUniversalCapability (tp : Type ): Boolean = tp match
489
+ case CapturingType (parent, ref) =>
490
+ ref.isUniversal || hasUniversalCapability(parent)
491
+ case tp =>
492
+ tp.isCapabilityClassRef || tp.parents.exists(hasUniversalCapability)
493
+
484
494
/** First half of result pair:
485
495
* Refine the type of a constructor call `new C(t_1, ..., t_n)`
486
496
* to C{val x_1: T_1, ..., x_m: T_m} where x_1, ..., x_m are the tracked
@@ -490,7 +500,8 @@ class CheckCaptures extends Recheck, SymTransformer:
490
500
*/
491
501
def addParamArgRefinements (core : Type , initCs : CaptureSet ): (Type , CaptureSet ) =
492
502
var refined : Type = core
493
- var allCaptures : CaptureSet = initCs
503
+ var allCaptures : CaptureSet = if hasUniversalCapability(core)
504
+ then CaptureSet .universal else initCs
494
505
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
495
506
val getter = cls.info.member(getterName).suchThat(_.is(ParamAccessor )).symbol
496
507
if getter.termRef.isTracked && ! getter.is(Private ) then
0 commit comments