scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Spurious reach capability error for assignment to a local variable

Open Linyxus opened this issue 1 year ago • 0 comments

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.

Linyxus avatar Aug 29 '24 12:08 Linyxus