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

Fields exposed as immutable references can be mutated when capturing them using a closure #361

Closed
yorickpeterse opened this issue Jan 25, 2023 · 0 comments · Fixed by #508
Labels
bug Defects, unintended behaviour, etc compiler Changes related to the compiler

Comments

@yorickpeterse
Copy link
Collaborator

When a closure captures a field, it exposes the field as a mut T even if the original type was ref T. As a result you can mutate immutable references to fields using a closure:

class Thing {
  let @values: Array[Int]

  fn example {
    fn { @values.pop } # This should error at compile-time, but it doesn't
  }
}
@yorickpeterse yorickpeterse added bug Defects, unintended behaviour, etc and removed type::bug labels Mar 15, 2023
@yorickpeterse yorickpeterse removed this from the 0.2.5 milestone Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Defects, unintended behaviour, etc compiler Changes related to the compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant