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

Leaking scoped capabilities #21401

Closed
Linyxus opened this issue Aug 20, 2024 · 1 comment · Fixed by #21428
Closed

Leaking scoped capabilities #21401

Linyxus opened this issue Aug 20, 2024 · 1 comment · Fixed by #21428
Assignees
Labels
area:experimental:cc Capture checking related itype:bug
Milestone

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Aug 20, 2024

Compiler version

main

Minimized code

import language.experimental.captureChecking

trait IO:
  def println(s: String): Unit
def usingIO[R](op: IO^ => R): R = ???

case class Boxed[+T](unbox: T)

type Res = [R, X <: Boxed[IO^] -> R] -> (op: X) -> R
def mkRes(x: IO^): Res =
  [R, X <: Boxed[IO^] -> R] => (op: X) =>
    val op1: Boxed[IO^] -> R = op
    op1(Boxed(x))
def test2(): Unit =
  val leaked: Res = usingIO[Res](mkRes)
  val x = leaked[Boxed[IO^], Boxed[IO^] -> Boxed[IO^]](x => x)
  x.unbox.println("boom")  // out of scope access to the scoped capability

Output

It compiles.

Expectation

It should not. It allows an out-of-scoped access to a scoped capability.

/cc @odersky

@Linyxus Linyxus added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:experimental:cc Capture checking related and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 20, 2024
@Linyxus
Copy link
Contributor Author

Linyxus commented Aug 23, 2024

At the latest main when compiling the code of this issue it outputs:

[info] running (fork) dotty.tools.dotc.Main -d /Users/linyxus/Workspace/dotty/compiler/../out/default-last-scalac-out.jar -classpath /Users/linyxus/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar:/Users/linyxus/Workspace/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.6.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.6.0-RC1-bin-SNAPSHOT.jar -color:never -Xprint:cc issues/cc-logging.scala
==> {cap} accountsFor (caps.cap : caps.Capability), {cap}??
<== {cap} accountsFor (caps.cap : caps.Capability), {cap}? = true
==> {cap} accountsFor ex$15.type, {ex$15}??
<== {cap} accountsFor ex$15.type, {ex$15}? = true

It shows the debug information!

This seems to a outcome of the combination of this and this.

/cc @odersky

@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants