Skip to content

Support basic inter-scope shadowing.#1472

Closed
kdashg wants to merge 1 commit intogpuweb:mainfrom
kdashg:shadowing-basic
Closed

Support basic inter-scope shadowing.#1472
kdashg wants to merge 1 commit intogpuweb:mainfrom
kdashg:shadowing-basic

Conversation

@kdashg
Copy link
Copy Markdown
Contributor

@kdashg kdashg commented Feb 26, 2021

Continue to forbid intra-scope shadowing.

var foo;
if (...) {
  var bar;
  var foo; // Allowed
  var bar; // Forbidden
}

Continue to forbid intra-scope shadowing.

```
var foo;
if (...) {
  var bar;
  var foo; // Allowed
  var bar; // Forbidden
}
```
declared.

A declaration must not introduce a name when that name is already in scope at the start
A declaration must not introduce a name when that name is already in the current scope at the start
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no global accounting of scopes, so "the current scope" is not well defined.

See #1511 (sorry for the implicit conflict).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have explained more...
#1511 says that the scope of a declared identifier is the range of source text over which the identifier denotes the declared object. So the set of scopes is 1-1 with the set of declarations.

We'd need different wording to support what you want.
What you want is tied to the brace-enclosed-block structure of the text. So we'd have a concept like scope-level which is is tied to a body_statement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just say that declarations in the function parameters or body would shadow the globals?

@dneto0
Copy link
Copy Markdown
Contributor

dneto0 commented Mar 15, 2021

There are pros and cons to allowing inter-scope shadowing.
Cons: It's often a programming error
Pros:

  • much better composability
  • like other common languages

On balance, Google is in favour of the intent of this change.

@dneto0
Copy link
Copy Markdown
Contributor

dneto0 commented Mar 24, 2021

Discussed in meeting of 2021-03-23

  • Consensus that the feature should be supported.
  • Will need a different PR, because the definition of "declaration" was overhauled in the meantime.

@dneto0
Copy link
Copy Markdown
Contributor

dneto0 commented Mar 24, 2021

Further work tracked by #1556

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

Successfully merging this pull request may close these issues.

3 participants