Skip to content

Commit 4c20f07

Browse files
committed
Charge deep capture set for use class params
1 parent 4cc0cf5 commit 4c20f07

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,14 @@ class CheckCaptures extends Recheck, SymTransformer:
834834
initCs ++ FreshCap(Origin.NewCapability(core)).readOnly.singletonCaptureSet
835835
else initCs
836836
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
837+
val paramSym = cls.primaryConstructor.paramNamed(getterName)
837838
val getter = cls.info.member(getterName).suchThat(_.isRefiningParamAccessor).symbol
838839
if !getter.is(Private) && getter.hasTrackedParts then
839840
refined = refined.refinedOverride(getterName, argType.unboxed) // Yichen you might want to check this
840-
allCaptures ++= argType.captureSet
841+
if paramSym.isUseParam then
842+
allCaptures ++= argType.deepCaptureSet
843+
else
844+
allCaptures ++= argType.captureSet
841845
(refined, allCaptures)
842846

843847
/** Augment result type of constructor with refinements and captures.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import language.experimental.captureChecking
2+
import caps.*
3+
class Runner(@use xs: List[() => Unit]):
4+
def execute: Unit = xs.foreach(op => op())
5+
def test1(@use ops: List[() => Unit]): Unit =
6+
val runner: Runner^{} = Runner(ops) // error
7+

0 commit comments

Comments
 (0)