@@ -728,20 +728,19 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
728728 else if cls.isPureClass then
729729 // is cls is known to be pure, nothing needs to be added to self type
730730 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))
737731 else if ! cls.isEffectivelySealed && ! cls.baseClassHasExplicitNonUniversalSelfType then
738732 // assume {cap} for completely unconstrained self types of publicly extensible classes
739733 CapturingType (cinfo.selfType, CaptureSet .universal)
740734 else
741735 // Infer the self type for the rest, which is all classes without explicit
742736 // self types (to which we also add nested module classes), provided they are
743737 // 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)
745744
746745 // Compute new parent types
747746 val ps1 = inContext(ctx.withOwner(cls)):
0 commit comments