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 local reach capability #21442

Closed
Linyxus opened this issue Aug 26, 2024 · 0 comments · Fixed by #21443
Closed

Leaking local reach capability #21442

Linyxus opened this issue Aug 26, 2024 · 0 comments · Fixed by #21443
Labels
area:experimental:cc Capture checking related itype:bug
Milestone

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Aug 26, 2024

Compiler version

main

Minimized code

import language.experimental.captureChecking
trait IO:
  def use(): Unit
case class Boxed[+T](unbox: T)

// `foo` is a function that unboxes its parameter
// and uses the capability boxed inside the parameter.
def foo(x: Boxed[IO^]): Unit =
  x.unbox.use()  // error: local reach capability {x*} leaks

// `bar` is a function that does the same thing in a
// slightly different way.
// But, no type error reported.
def bar(x: Boxed[IO^]): Unit =
  val x1: Boxed[IO^] = x
  val io = x1.unbox
  io.use()

Output

-- Error: issues/localreach.scala:9:4 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9 |  x.unbox.use()  // error: local reach capability {x*} leaks
  |  ^^^^^^^
  |  Local reach capability x* leaks into capture scope of method foo

(only one error reported)

Expectation

Both functions should have a type error.

/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 26, 2024
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2024
@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
@Linyxus @WojciechMazur and others