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

Variable with boxed function allows call of function without necessary captures in scope #537

Closed
dvdvgt opened this issue Aug 6, 2024 · 1 comment
Labels
area:compiler area:typer bug Something isn't working

Comments

@dvdvgt
Copy link
Collaborator

dvdvgt commented Aug 6, 2024

Consider this program:

interface Greet { def sayHello(): Unit }

def main() = {
  var f = box { () }
  try { f = box { g.sayHello() } }
  with g: Greet { def sayHello() = println("hello!") }
  f()
}

This should of course fail at compile-time since at the call-site of f, the capture g is not in scope. However, it fails with the following error at runtime:

Prompt 2 not found

The type of f is inferred as () => Unit at { g }. Thus, the first assignment is also valid due to capture subtyping. If you actually try to annotate it like this, you cannot since g is not in scope (TIL this is called a Voldemort type according to @jiribenes)

If you instead annotate f with the type of its first assignment, the program expectedly fails at compile-time:

interface Greet { def sayHello(): Unit }

def main() = {
  var f: () => Unit at {} = box { () }
  try { f = box { g.sayHello() } }
  with g: Greet { def sayHello() = println("hello!") }
  f()
}
@dvdvgt dvdvgt added bug Something isn't working area:compiler area:typer labels Aug 6, 2024
@b-studios
Copy link
Collaborator

Potentially fixed by #552

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:compiler area:typer bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants