Skip to content
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

No need to unbox if expected type is LhsProto #21508

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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