Skip to content

Commit 28eb166

Browse files
committed
Disallow nested capabilitirs in self types of classes
Also: Factor out Vars that are part of inferred types of vals and defs as ProperVars.
1 parent 0ec9468 commit 28eb166

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,10 @@ object CaptureSet:
954954
class RefiningVar(owner: Symbol)(using Context) extends Var(owner):
955955
override def disallowBadRoots(upto: Symbol)(handler: () => Context ?=> Unit)(using Context) = this
956956

957+
/** Variables created in types of inferred type trees */
958+
class ProperVar(override val owner: Symbol, initialElems: Refs, nestedOK: Boolean)(using /*@constructorOnly*/ ictx: Context)
959+
extends Var(owner, initialElems, nestedOK)
960+
957961
/** A variable that is derived from some other variable via a map or filter. */
958962
abstract class DerivedVar(owner: Symbol, initialElems: Refs)(using @constructorOnly ctx: Context)
959963
extends Var(owner, initialElems):

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
685685
// Infer the self type for the rest, which is all classes without explicit
686686
// self types (to which we also add nested module classes), provided they are
687687
// neither pure, nor are publicily extensible with an unconstrained self type.
688-
val cs = CaptureSet.Var(cls)
688+
val cs = CaptureSet.ProperVar(cls, CaptureSet.emptyRefs, nestedOK = false)
689689
if cls.derivesFrom(defn.Caps_Capability) then
690690
// If cls is a capability class, we need to add a fresh readonly capability to
691691
// ensure we cannot treat the class as pure.
@@ -852,7 +852,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
852852

853853
/** Add a capture set variable to `tp` if necessary. */
854854
private def addVar(tp: Type, owner: Symbol)(using Context): Type =
855-
decorate(tp, CaptureSet.Var(owner, _, nestedOK = !ctx.mode.is(Mode.CCPreciseOwner)))
855+
decorate(tp, CaptureSet.ProperVar(owner, _, nestedOK = !ctx.mode.is(Mode.CCPreciseOwner)))
856856

857857
/** A map that adds <fluid> capture sets at all contra- and invariant positions
858858
* in a type where a capture set would be needed. This is used to make types

0 commit comments

Comments
 (0)