Skip to content

Experiment with Capless-like Scheme for Capture Checking #23291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Charge deep capture set for use class params
  • Loading branch information
Linyxus committed Jun 9, 2025
commit 4c20f079119dbff66babb9ba5af4abcac24b09ca
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,14 @@ class CheckCaptures extends Recheck, SymTransformer:
initCs ++ FreshCap(Origin.NewCapability(core)).readOnly.singletonCaptureSet
else initCs
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
val paramSym = cls.primaryConstructor.paramNamed(getterName)
val getter = cls.info.member(getterName).suchThat(_.isRefiningParamAccessor).symbol
if !getter.is(Private) && getter.hasTrackedParts then
refined = refined.refinedOverride(getterName, argType.unboxed) // Yichen you might want to check this
allCaptures ++= argType.captureSet
if paramSym.isUseParam then
allCaptures ++= argType.deepCaptureSet
else
allCaptures ++= argType.captureSet
(refined, allCaptures)

/** Augment result type of constructor with refinements and captures.
Expand Down
7 changes: 7 additions & 0 deletions tests/neg-custom-args/captures/cc-class-reach.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import language.experimental.captureChecking
import caps.*
class Runner(@use xs: List[() => Unit]):
def execute: Unit = xs.foreach(op => op())
def test1(@use ops: List[() => Unit]): Unit =
val runner: Runner^{} = Runner(ops) // error