@@ -519,6 +519,16 @@ class CheckCaptures extends Recheck, SymTransformer:
519519 if sym.isConstructor then
520520 val cls = sym.owner.asClass
521521
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+
522532 /** First half of result pair:
523533 * Refine the type of a constructor call `new C(t_1, ..., t_n)`
524534 * 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:
528538 */
529539 def addParamArgRefinements (core : Type , initCs : CaptureSet ): (Type , CaptureSet ) =
530540 var refined : Type = core
531- var allCaptures : CaptureSet = initCs
541+ var allCaptures : CaptureSet = if hasUniversalCapability(core)
542+ then CaptureSet .universal else initCs
532543 for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
533544 val getter = cls.info.member(getterName).suchThat(_.is(ParamAccessor )).symbol
534545 if getter.termRef.isTracked && ! getter.is(Private ) then
0 commit comments