Conversation
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 |
There was a problem hiding this comment.
There is no global accounting of scopes, so "the current scope" is not well defined.
See #1511 (sorry for the implicit conflict).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Can we just say that declarations in the function parameters or body would shadow the globals?
|
There are pros and cons to allowing inter-scope shadowing.
On balance, Google is in favour of the intent of this change. |
|
Discussed in meeting of 2021-03-23
|
|
Further work tracked by #1556 |
Continue to forbid intra-scope shadowing.