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

clarify scoping rules #56

Open
ckp95 opened this issue Feb 25, 2023 · 0 comments
Open

clarify scoping rules #56

ckp95 opened this issue Feb 25, 2023 · 0 comments

Comments

@ckp95
Copy link
Contributor

ckp95 commented Feb 25, 2023

The spec doesn't lay out the precise rules for variable scoping. I didn't find any surprises but I still had to discover them by experimentation. This is what I gathered:

  • lexical block scoping for functions, methods, if/case/for/while etc
  • a new variable defined in a if/case/for/while does not outlive the block even if it has the same name and type in all branches
  • you can't use let to re-define an existing variable, even if it was made in an outer scope (no shadowing)
  • if a linear variable is borrowed in a borrow block, it vanishes for the duration of the borrow block then reappears afterwards

Is this a fair description?


oh also the let-destructure section doesn't talk about the optional as fragment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant