-
Notifications
You must be signed in to change notification settings - Fork 816
Port PR #61376: Fix spurious "used before being assigned" errors in for of/in loops #2462
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
Merged
+416
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
testdata/baselines/reference/compiler/unusedLocalsInForInOrOf1.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| unusedLocalsInForInOrOf1.ts(2,12): error TS6133: 'f' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(8,7): error TS6133: 'f' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(14,12): error TS6133: 'g' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(20,12): error TS6133: 'f2' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(26,7): error TS6133: 'f2' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(32,12): error TS6133: 'g2' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(38,12): error TS6133: 'f3' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(44,7): error TS6133: 'f3' is declared but its value is never read. | ||
| unusedLocalsInForInOrOf1.ts(50,12): error TS6133: 'g3' is declared but its value is never read. | ||
|
|
||
|
|
||
| ==== unusedLocalsInForInOrOf1.ts (9 errors) ==== | ||
| for (let x of [1, 2]) { | ||
| function f() { | ||
| ~ | ||
| !!! error TS6133: 'f' is declared but its value is never read. | ||
| x; | ||
| } | ||
| } | ||
|
|
||
| for (let x of [1, 2]) { | ||
| let f = () => { | ||
| ~ | ||
| !!! error TS6133: 'f' is declared but its value is never read. | ||
| x; | ||
| }; | ||
| } | ||
|
|
||
| for (const x of [1, 2]) { | ||
| function g() { | ||
| ~ | ||
| !!! error TS6133: 'g' is declared but its value is never read. | ||
| x; | ||
| } | ||
| } | ||
|
|
||
| for (let x in { a: 1, b: 2 }) { | ||
| function f2() { | ||
| ~~ | ||
| !!! error TS6133: 'f2' is declared but its value is never read. | ||
| x; | ||
| } | ||
| } | ||
|
|
||
| for (let x in { a: 1, b: 2 }) { | ||
| let f2 = () => { | ||
| ~~ | ||
| !!! error TS6133: 'f2' is declared but its value is never read. | ||
| x; | ||
| }; | ||
| } | ||
|
|
||
| for (const x in { a: 1, b: 2 }) { | ||
| function g2() { | ||
| ~~ | ||
| !!! error TS6133: 'g2' is declared but its value is never read. | ||
| x; | ||
| } | ||
| } | ||
|
|
||
| for (let { x } of [{ x: 1 }, { x: 2 }]) { | ||
| function f3() { | ||
| ~~ | ||
| !!! error TS6133: 'f3' is declared but its value is never read. | ||
| x; | ||
| } | ||
| } | ||
|
|
||
| for (let { x } of [{ x: 1 }, { x: 2 }]) { | ||
| let f3 = () => { | ||
| ~~ | ||
| !!! error TS6133: 'f3' is declared but its value is never read. | ||
| x; | ||
| }; | ||
| } | ||
|
|
||
| for (const { x } of [{ x: 1 }, { x: 2 }]) { | ||
| function g3() { | ||
| ~~ | ||
| !!! error TS6133: 'g3' is declared but its value is never read. | ||
| x; | ||
| } | ||
| } | ||
|
|
117 changes: 117 additions & 0 deletions
117
testdata/baselines/reference/compiler/unusedLocalsInForInOrOf1.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| //// [tests/cases/compiler/unusedLocalsInForInOrOf1.ts] //// | ||
|
|
||
| === unusedLocalsInForInOrOf1.ts === | ||
| for (let x of [1, 2]) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 0, 8)) | ||
|
|
||
| function f() { | ||
| >f : Symbol(f, Decl(unusedLocalsInForInOrOf1.ts, 0, 23)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 0, 8)) | ||
| } | ||
| } | ||
|
|
||
| for (let x of [1, 2]) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 6, 8)) | ||
|
|
||
| let f = () => { | ||
| >f : Symbol(f, Decl(unusedLocalsInForInOrOf1.ts, 7, 5)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 6, 8)) | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| for (const x of [1, 2]) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 12, 10)) | ||
|
|
||
| function g() { | ||
| >g : Symbol(g, Decl(unusedLocalsInForInOrOf1.ts, 12, 25)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 12, 10)) | ||
| } | ||
| } | ||
|
|
||
| for (let x in { a: 1, b: 2 }) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 18, 8)) | ||
| >a : Symbol(a, Decl(unusedLocalsInForInOrOf1.ts, 18, 15)) | ||
| >b : Symbol(b, Decl(unusedLocalsInForInOrOf1.ts, 18, 21)) | ||
|
|
||
| function f2() { | ||
| >f2 : Symbol(f2, Decl(unusedLocalsInForInOrOf1.ts, 18, 31)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 18, 8)) | ||
| } | ||
| } | ||
|
|
||
| for (let x in { a: 1, b: 2 }) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 24, 8)) | ||
| >a : Symbol(a, Decl(unusedLocalsInForInOrOf1.ts, 24, 15)) | ||
| >b : Symbol(b, Decl(unusedLocalsInForInOrOf1.ts, 24, 21)) | ||
|
|
||
| let f2 = () => { | ||
| >f2 : Symbol(f2, Decl(unusedLocalsInForInOrOf1.ts, 25, 5)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 24, 8)) | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| for (const x in { a: 1, b: 2 }) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 30, 10)) | ||
| >a : Symbol(a, Decl(unusedLocalsInForInOrOf1.ts, 30, 17)) | ||
| >b : Symbol(b, Decl(unusedLocalsInForInOrOf1.ts, 30, 23)) | ||
|
|
||
| function g2() { | ||
| >g2 : Symbol(g2, Decl(unusedLocalsInForInOrOf1.ts, 30, 33)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 30, 10)) | ||
| } | ||
| } | ||
|
|
||
| for (let { x } of [{ x: 1 }, { x: 2 }]) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 36, 10)) | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 36, 20)) | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 36, 30)) | ||
|
|
||
| function f3() { | ||
| >f3 : Symbol(f3, Decl(unusedLocalsInForInOrOf1.ts, 36, 41)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 36, 10)) | ||
| } | ||
| } | ||
|
|
||
| for (let { x } of [{ x: 1 }, { x: 2 }]) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 42, 10)) | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 42, 20)) | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 42, 30)) | ||
|
|
||
| let f3 = () => { | ||
| >f3 : Symbol(f3, Decl(unusedLocalsInForInOrOf1.ts, 43, 5)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 42, 10)) | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| for (const { x } of [{ x: 1 }, { x: 2 }]) { | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 48, 12)) | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 48, 22)) | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 48, 32)) | ||
|
|
||
| function g3() { | ||
| >g3 : Symbol(g3, Decl(unusedLocalsInForInOrOf1.ts, 48, 43)) | ||
|
|
||
| x; | ||
| >x : Symbol(x, Decl(unusedLocalsInForInOrOf1.ts, 48, 12)) | ||
| } | ||
| } | ||
|
|
153 changes: 153 additions & 0 deletions
153
testdata/baselines/reference/compiler/unusedLocalsInForInOrOf1.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| //// [tests/cases/compiler/unusedLocalsInForInOrOf1.ts] //// | ||
|
|
||
| === unusedLocalsInForInOrOf1.ts === | ||
| for (let x of [1, 2]) { | ||
| >x : number | ||
| >[1, 2] : number[] | ||
| >1 : 1 | ||
| >2 : 2 | ||
|
|
||
| function f() { | ||
| >f : () => void | ||
|
|
||
| x; | ||
| >x : number | ||
| } | ||
| } | ||
|
|
||
| for (let x of [1, 2]) { | ||
| >x : number | ||
| >[1, 2] : number[] | ||
| >1 : 1 | ||
| >2 : 2 | ||
|
|
||
| let f = () => { | ||
| >f : () => void | ||
| >() => { x; } : () => void | ||
|
|
||
| x; | ||
| >x : number | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| for (const x of [1, 2]) { | ||
| >x : number | ||
| >[1, 2] : number[] | ||
| >1 : 1 | ||
| >2 : 2 | ||
|
|
||
| function g() { | ||
| >g : () => void | ||
|
|
||
| x; | ||
| >x : number | ||
| } | ||
| } | ||
|
|
||
| for (let x in { a: 1, b: 2 }) { | ||
| >x : string | ||
| >{ a: 1, b: 2 } : { a: number; b: number; } | ||
| >a : number | ||
| >1 : 1 | ||
| >b : number | ||
| >2 : 2 | ||
|
|
||
| function f2() { | ||
| >f2 : () => void | ||
|
|
||
| x; | ||
| >x : string | ||
| } | ||
| } | ||
|
|
||
| for (let x in { a: 1, b: 2 }) { | ||
| >x : string | ||
| >{ a: 1, b: 2 } : { a: number; b: number; } | ||
| >a : number | ||
| >1 : 1 | ||
| >b : number | ||
| >2 : 2 | ||
|
|
||
| let f2 = () => { | ||
| >f2 : () => void | ||
| >() => { x; } : () => void | ||
|
|
||
| x; | ||
| >x : string | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| for (const x in { a: 1, b: 2 }) { | ||
| >x : string | ||
| >{ a: 1, b: 2 } : { a: number; b: number; } | ||
| >a : number | ||
| >1 : 1 | ||
| >b : number | ||
| >2 : 2 | ||
|
|
||
| function g2() { | ||
| >g2 : () => void | ||
|
|
||
| x; | ||
| >x : string | ||
| } | ||
| } | ||
|
|
||
| for (let { x } of [{ x: 1 }, { x: 2 }]) { | ||
| >x : number | ||
| >[{ x: 1 }, { x: 2 }] : { x: number; }[] | ||
| >{ x: 1 } : { x: number; } | ||
| >x : number | ||
| >1 : 1 | ||
| >{ x: 2 } : { x: number; } | ||
| >x : number | ||
| >2 : 2 | ||
|
|
||
| function f3() { | ||
| >f3 : () => void | ||
|
|
||
| x; | ||
| >x : number | ||
| } | ||
| } | ||
|
|
||
| for (let { x } of [{ x: 1 }, { x: 2 }]) { | ||
| >x : number | ||
| >[{ x: 1 }, { x: 2 }] : { x: number; }[] | ||
| >{ x: 1 } : { x: number; } | ||
| >x : number | ||
| >1 : 1 | ||
| >{ x: 2 } : { x: number; } | ||
| >x : number | ||
| >2 : 2 | ||
|
|
||
| let f3 = () => { | ||
| >f3 : () => void | ||
| >() => { x; } : () => void | ||
|
|
||
| x; | ||
| >x : number | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| for (const { x } of [{ x: 1 }, { x: 2 }]) { | ||
| >x : number | ||
| >[{ x: 1 }, { x: 2 }] : { x: number; }[] | ||
| >{ x: 1 } : { x: number; } | ||
| >x : number | ||
| >1 : 1 | ||
| >{ x: 2 } : { x: number; } | ||
| >x : number | ||
| >2 : 2 | ||
|
|
||
| function g3() { | ||
| >g3 : () => void | ||
|
|
||
| x; | ||
| >x : number | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.