On Nov 13, 2013, at 3:41 PM, Ian Halliday wrote:
> Wait, so is there no variable shadowing allowed then?
this is saying that things like the following are illegal:
{var x;
let x;
}
But shadowing, like the following is fine:
var x;
{let x;
}
>
> 13.1.1 Static Semantics: Early Errors
>
> Block : { StatementList }
> · It is a Syntax Error if the LexicallyDeclaredNames of StatementList
> contains any duplicate entries.
>
> · It is a Syntax Error if any element of the LexicallyDeclaredNames
> of StatementList also occurs in the VarDeclaredNames ofStatementList.
>
> StatementList can contain Blocks whose LexicallyDeclaredNames and
> VarDeclaredNames algorithms return the values for their StatementLists, so it
> recursively collects the names from all nested lexical and var declarations.
>
> It looks like VarDeclaredNames is missing a definition for VariableStatement
> because I can’t see any way for the bound names of a VariableStatement to get
> added to VarDeclaredNames lists.
>
> But barring for the moment that I cannot find an algorithm definition that
> adds BoundNames of a VariableStatement to VarDeclaredNames, this second early
> error bullet implies that shadowing of bound names is not allowed at all.
>
> Is this correct?
>
> Ian
>
>
> From: Allen Wirfs-Brock [mailto:[email protected]]
> Sent: Friday, November 8, 2013 4:16 PM
> To: Ian Halliday
> Cc: [email protected]
> Subject: Re: Specification of use before declaration errors
>
>
> On Nov 8, 2013, at 3:35 PM, Ian Halliday wrote:
>
>
> Hello es-discuss,
>
> I’m having difficulty figuring out where the ES6 draft spec specifies that a
> “use before declaration” error should be thrown. My last understanding of
> the temporal dead zone was that ECMAScript would always issue a “use before
> declaration” error at runtime, regardless whether it can be statically
> determined or not. However it seems like the evaluation semantics of var
> declarations, for example, do not lead to any line that throws a
> ReferenceError.
>
>
>
> That is, consider this code:
>
> function f() {
> {
> var x = 5;
> let x;
> declaring the same name using a let and a var is an early error:
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-block-static-semantics-early-errors
>
> or for the function level
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function-definitions-static-semantics-early-errors
>
>
>
>
> }
> }
>
> f();
>
> I think the var declaration creates a binding for x in the function’s lexical
> environment, but then binds to the x in the block’s environment for the
> initialization. As such, the initialization should throw a “use before
> declaration” error. But this is what I cannot find in the spec. Maybe I am
> wrong about the semantics here?
>
> because an early error exists, the surround script or module is never
> evaluated.
>
> Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss