Skip to content

Commit c89072c

Browse files
committed
Fix checkNotGlobal condition for root capture set
1 parent da82287 commit c89072c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class CheckCaptures extends Recheck:
9595
val ref = sym.termRef
9696
def recur(env: Env): Unit =
9797
if env.isOpen && env.owner != sym.enclosure then
98+
capt.println(i"Mark $sym free in ${env.owner}")
9899
checkElem(ref, env.captured, pos)
99100
recur(env.outer)
100101
if ref.isTracked then recur(curEnv)
@@ -153,7 +154,7 @@ class CheckCaptures extends Recheck:
153154

154155
override def recheck(tree: Tree, pt: Type = WildcardType)(using Context): Type =
155156
val saved = curEnv
156-
if pt.needsBox && !curEnv.isBoxed then
157+
if pt.needsBox && !curEnv.isBoxed && false then // ^^^ refine
157158
curEnv = Env(NoSymbol, CaptureSet.Var(), true, curEnv)
158159
try
159160
val res = super.recheck(tree, pt)
@@ -171,15 +172,14 @@ class CheckCaptures extends Recheck:
171172

172173
def checkNotGlobal(tree: Tree, allArgs: Tree*)(using Context): Unit =
173174
if disallowGlobal then
174-
//println(i"checking $arg in $tree: ${arg.tpe.captureSet}")
175175
tree match
176176
case LambdaTypeTree(_, restpt) =>
177177
checkNotGlobal(restpt, allArgs*)
178178
case _ =>
179179
for ref <- tree.tpe.captureSet.elems do
180180
val isGlobal = ref match
181-
case ref: TypeRef => ref.isRootCapability
182-
case ref: TermRef => ref.prefix != NoPrefix && ref.symbol.hasAnnotation(defn.AbilityAnnot)
181+
case ref: TermRef =>
182+
ref.isRootCapability || ref.prefix != NoPrefix && ref.symbol.hasAnnotation(defn.AbilityAnnot)
183183
case _ => false
184184
val what = if ref.isRootCapability then "universal" else "global"
185185
if isGlobal then
@@ -196,7 +196,9 @@ class CheckCaptures extends Recheck:
196196
def traverse(tree: Tree)(using Context) =
197197
tree match
198198
case tree1 @ TypeApply(fn, args) if disallowGlobal =>
199-
for arg <- args do checkNotGlobal(arg, args*)
199+
for arg <- args do
200+
//println(i"checking $arg in $tree: ${arg.tpe.captureSet}")
201+
checkNotGlobal(arg, args*)
200202
case _ =>
201203
traverseChildren(tree)
202204

0 commit comments

Comments
 (0)