Skip to content

Dependent function application can leak a scoped capability #17517

Closed
@Linyxus

Description

@Linyxus

Compiler version

main branch

Minimized code

import language.experimental.captureChecking
import java.io.*

object Test:
  class Logger(f: OutputStream^):
    def log(msg: String): Unit = ???

  def usingFile[sealed T](name: String, op: OutputStream^ => T): T =
    val f = new FileOutputStream(name)
    val result = op(f)
    f.close()
    result

  def usingLogger[sealed T](f: OutputStream^)(op: Logger^{f} => T): T = ???

  usingFile(
    "foo",
    file => {
      usingLogger(file)(l => () => l.log("test"))  // leaking the local logger
    }
  )  // should be error but it compiles

Output

It compiles, but the last lines should be rejected since the scoped capability is leaked in the result.

Expectation

There should be an error on the last lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cc-experimentIntended to be merged with cc-experiment branch on originitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions