@@ -728,20 +728,19 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
728
728
else if cls.isPureClass then
729
729
// is cls is known to be pure, nothing needs to be added to self type
730
730
selfInfo
731
- else if cls.derivesFrom(defn.Caps_Capability ) then
732
- // If cls is a capability class, we need to add a fresh capability to
733
- // ensure we cannot treat itself as pure.
734
- CapturingType (cinfo.selfType,
735
- CaptureSet .fresh(Origin .InDecl (cls)).readOnly
736
- ++ CaptureSet .Var (cls, level = ccState.currentLevel))
737
731
else if ! cls.isEffectivelySealed && ! cls.baseClassHasExplicitNonUniversalSelfType then
738
732
// assume {cap} for completely unconstrained self types of publicly extensible classes
739
733
CapturingType (cinfo.selfType, CaptureSet .universal)
740
734
else
741
735
// Infer the self type for the rest, which is all classes without explicit
742
736
// self types (to which we also add nested module classes), provided they are
743
737
// neither pure, nor are publicily extensible with an unconstrained self type.
744
- CapturingType (cinfo.selfType, CaptureSet .Var (cls, level = ccState.currentLevel))
738
+ val cs = CaptureSet .Var (cls, level = ccState.currentLevel)
739
+ if cls.derivesFrom(defn.Caps_Capability ) then
740
+ // If cls is a capability class, we need to add a fresh readonly capability to
741
+ // ensure we cannot treat the class as pure.
742
+ CaptureSet .fresh(Origin .InDecl (cls)).readOnly.subCaptures(cs)
743
+ CapturingType (cinfo.selfType, cs)
745
744
746
745
// Compute new parent types
747
746
val ps1 = inContext(ctx.withOwner(cls)):
0 commit comments