Skip to content

Commit c137b5a

Browse files
committed
Find universal capability from parents
1 parent a36849f commit c137b5a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ class CheckCaptures extends Recheck, SymTransformer:
481481
if sym.isConstructor then
482482
val cls = sym.owner.asClass
483483

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+
484494
/** First half of result pair:
485495
* Refine the type of a constructor call `new C(t_1, ..., t_n)`
486496
* 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:
490500
*/
491501
def addParamArgRefinements(core: Type, initCs: CaptureSet): (Type, CaptureSet) =
492502
var refined: Type = core
493-
var allCaptures: CaptureSet = initCs
503+
var allCaptures: CaptureSet = if hasUniversalCapability(core)
504+
then CaptureSet.universal else initCs
494505
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
495506
val getter = cls.info.member(getterName).suchThat(_.is(ParamAccessor)).symbol
496507
if getter.termRef.isTracked && !getter.is(Private) then

0 commit comments

Comments
 (0)