Skip to content

Commit 3097a84

Browse files
authored
No need to unbox if expected type is LhsProto (#21508)
fixes #21507
2 parents b8c5ecb + a045b8c commit 3097a84

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ class CheckCaptures extends Recheck, SymTransformer:
969969
if tree.isTerm then
970970
if !ccConfig.useExistentials then
971971
checkReachCapsIsolated(res.widen, tree.srcPos)
972-
if !pt.isBoxedCapturing then
972+
if !pt.isBoxedCapturing && pt != LhsProto then
973973
markFree(res.boxedCaptureSet, tree.srcPos)
974974
res
975975

Diff for: tests/pos-custom-args/captures/i21507.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import language.experimental.captureChecking
2+
3+
trait Box[Cap^]:
4+
def store(f: (() -> Unit)^{Cap^}): Unit
5+
6+
def run[Cap^](f: Box[Cap]^{Cap^} => Unit): Box[Cap]^{Cap^} =
7+
new Box[Cap]:
8+
private var item: () ->{Cap^} Unit = () => ()
9+
def store(f: () ->{Cap^} Unit): Unit =
10+
item = f // was error, now ok

0 commit comments

Comments
 (0)