diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index ec134149eb49..b05ab8542137 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -969,7 +969,7 @@ class CheckCaptures extends Recheck, SymTransformer: if tree.isTerm then if !ccConfig.useExistentials then checkReachCapsIsolated(res.widen, tree.srcPos) - if !pt.isBoxedCapturing then + if !pt.isBoxedCapturing && pt != LhsProto then markFree(res.boxedCaptureSet, tree.srcPos) res diff --git a/tests/pos-custom-args/captures/i21507.scala b/tests/pos-custom-args/captures/i21507.scala new file mode 100644 index 000000000000..bb80dafb3b45 --- /dev/null +++ b/tests/pos-custom-args/captures/i21507.scala @@ -0,0 +1,10 @@ +import language.experimental.captureChecking + +trait Box[Cap^]: + def store(f: (() -> Unit)^{Cap^}): Unit + +def run[Cap^](f: Box[Cap]^{Cap^} => Unit): Box[Cap]^{Cap^} = + new Box[Cap]: + private var item: () ->{Cap^} Unit = () => () + def store(f: () ->{Cap^} Unit): Unit = + item = f // was error, now ok