Skip to content

clarify scoping rules #56

Description

@ckp95

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions