Skip to content

'let' should not be allowed to be bound as a variable in a for-of loop or let/const decl #3475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue Jun 11, 2015 · 3 comments · Fixed by #5898
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

The following examples should trigger an early error in JS:

let let = 10;
const let = 10;

Note: a similar test exists in tests/cases/conformance/es6/for-ofStatements/for-of56.ts) for the following 3 examples

for (var let of [1,2,3]) {
}
for (let let of [1,2,3]) {
}
for (const let of [1,2,3]) {
}

I'm not sure if the following should trigger an error:

var let = 10;
for (let of [1,2,3]) {
}


13.2.1.1 Static Semantics: Early Errors

LexicalDeclaration : LetOrConst BindingList ;

  • It is a Syntax Error if the BoundNames of BindingList contains "let".

13.6.4.1 Static Semantics: Early Errors

IterationStatement :

for ( ForDeclaration in Expression ) Statement

for ( ForDeclaration of AssignmentExpression ) Statement

  • It is a Syntax Error if the BoundNames of ForDeclaration contains "let".
@yuit
Copy link
Contributor

yuit commented Jul 9, 2015

var let = 10;
for (let of [1,2,3]) {
}

This should trigger an early error from this grammar production

for ( [lookahead ≠ let ] LeftHandSideExpression[?Yield] of AssignmentExpression[In, ?Yield] ) 

@DanielRosenwasser DanielRosenwasser changed the title 'let' should not be allowed to be bound as a variable in a for loop or let/const decl 'let' should not be allowed to be bound as a variable in a for-of loop or let/const decl Jul 9, 2015
@DanielRosenwasser
Copy link
Member Author

Yup - it would be useful to have a test like

var let: number[] = []
let i = false
let s = 0
for (let[i] of [[1],[2],[3],[4],[5]]) {
    s += i
}

As well as one like this:

var let: number[] = []
let i = 0
let s = 0
for ((let[i]) of [1,2,3,4,5]) {
    s += let[i]
    i++
}

Neither of these should error.

@mhegazy mhegazy modified the milestones: TypeScript 1.7, TypeScript 1.6 Jul 9, 2015
@yuit yuit modified the milestones: TypeScript 1.6, TypeScript 1.7 Jul 14, 2015
@mhegazy mhegazy modified the milestones: TypeScript 1.7, TypeScript 1.8 Oct 9, 2015
@yuit yuit closed this as completed in #5898 Dec 4, 2015
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 4, 2015
@DanielRosenwasser
Copy link
Member Author

💯

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants