Skip to content

Spurious reach capability error for assignment to a local variable #21507

Closed
@Linyxus

Description

@Linyxus

Compiler version

main

Minimized code

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

Output

-- Error: issues/box-store.scala:9:43 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9 |    def store(f: () ->{Cap^} Unit): Unit = item = f
  |                                           ^^^^
  |                                           Local reach capability Cap leaks into capture scope of method run
1 error found

Expectation

There should not be an error.

From @natsukagami when he was capture checking gears.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions