Skip to content

Generator object body scope is surprising #1593

Description

@bioball

This snippet:

qux = "outer"

foo {
  when (true) {
    local qux = "inner"
  }
  prop = qux
}

Produces:

qux = "outer"
foo {
  prop = "inner"
}

This is because generator object bodies are visible to the enclosing object.

Sometimes, names resolve either to a generator property, and sometimes, they resolve to an outer property. At parse time, we can't tell what these should resolve to. For example:

qux = "outer"

foo {
  when (true) {
    qux = "inner"
  }
  prop = qux // resolves to inner qux
}

bar {
  when (false) {
    qux = "inner"
  }
  prop = qux // resolves to outer qux
}

It would be better if names declared inside of generator bodies are not visible from an enclosing object body.
Most code would still work if it resolved to implicit this.

We need to fix this before we can do #1580

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