Skip to content

Capture checking does not cover values in scope #19855

Open
@markehammons

Description

@markehammons

Compiler version

3.4.0

Minimized code

import language.experimental.captureChecking
import scala.annotation.capability

@capability class Executor

val global: Executor = Executor()

def fn[A](fn: => A)(exec: Executor): Int^{exec} = 5

val myFn1: Int -> Int = fn(_)(global)
val myFn2: Int -> Int = i => {fn(i)(global); 5}

Output

Both myFn1 and myFn2 compile.

Expectation

myFn1 and myFn2 capture the global executor here. Since the capture set of the closure is empty, they should not be able to do this.
I'll note that changing myFn1 and myFn2 to be methods that take a method parameter, which is then used in the call to fn results in them both complaining about the capture.

def myFn1(exec: Executor): Int -> Int = fn(_)(exec) //error here
def myFn2(exec: Executor): Int -> Int = i => {fn(i)(exec); 5} //error here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions