Skip to content

Commit

Permalink
No need to unbox if expected type is LhsProto (#21508)
Browse files Browse the repository at this point in the history
fixes #21507
  • Loading branch information
odersky authored Sep 23, 2024
2 parents b8c5ecb + a045b8c commit 3097a84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions tests/pos-custom-args/captures/i21507.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3097a84

Please sign in to comment.