Skip to content

Commit 8cb85c2

Browse files
committed
Charge deep capture set for use class params
1 parent 844d70a commit 8cb85c2

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
@@ -846,10 +846,14 @@ class CheckCaptures extends Recheck, SymTransformer:
846846
initCs ++ FreshCap(Origin.NewCapability(core)).readOnly.singletonCaptureSet
847847
else initCs
848848
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
849+
val paramSym = cls.primaryConstructor.paramNamed(getterName)
849850
val getter = cls.info.member(getterName).suchThat(_.isRefiningParamAccessor).symbol
850851
if !getter.is(Private) && getter.hasTrackedParts then
851852
refined = refined.refinedOverride(getterName, argType.unboxed) // Yichen you might want to check this
852-
allCaptures ++= argType.captureSet
853+
if paramSym.isUseParam then
854+
allCaptures ++= argType.deepCaptureSet
855+
else
856+
allCaptures ++= argType.captureSet
853857
(refined, allCaptures)
854858

855859
/** 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)