@@ -519,6 +519,16 @@ class CheckCaptures extends Recheck, SymTransformer:
519
519
if sym.isConstructor then
520
520
val cls = sym.owner.asClass
521
521
522
+ /** Check if the class or one of its parents has a root capability,
523
+ * which means that the class has a capability annotation or an impure
524
+ * function type.
525
+ */
526
+ def hasUniversalCapability (tp : Type ): Boolean = tp match
527
+ case CapturingType (parent, ref) =>
528
+ ref.isUniversal || hasUniversalCapability(parent)
529
+ case tp =>
530
+ tp.isCapabilityClassRef || tp.parents.exists(hasUniversalCapability)
531
+
522
532
/** First half of result pair:
523
533
* Refine the type of a constructor call `new C(t_1, ..., t_n)`
524
534
* to C{val x_1: T_1, ..., x_m: T_m} where x_1, ..., x_m are the tracked
@@ -528,7 +538,8 @@ class CheckCaptures extends Recheck, SymTransformer:
528
538
*/
529
539
def addParamArgRefinements (core : Type , initCs : CaptureSet ): (Type , CaptureSet ) =
530
540
var refined : Type = core
531
- var allCaptures : CaptureSet = initCs
541
+ var allCaptures : CaptureSet = if hasUniversalCapability(core)
542
+ then CaptureSet .universal else initCs
532
543
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
533
544
val getter = cls.info.member(getterName).suchThat(_.is(ParamAccessor )).symbol
534
545
if getter.termRef.isTracked && ! getter.is(Private ) then
0 commit comments