-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue with for statement's incrementor missing continue's co…
…ntrol flow information (#60950)
- Loading branch information
Showing
5 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
45 changes: 45 additions & 0 deletions
45
tests/baselines/reference/controlFlowForStatementContinueIntoIncrementor1.errors.txt
This file contains 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,45 @@ | ||
controlFlowForStatementContinueIntoIncrementor1.ts(8,5): error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
controlFlowForStatementContinueIntoIncrementor1.ts(23,5): error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== controlFlowForStatementContinueIntoIncrementor1.ts (2 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/60945 | ||
|
||
{ | ||
let iNext; | ||
for ( | ||
let i = 0; | ||
i < 10; | ||
i = iNext // error | ||
~ | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
) { | ||
if (i == 5) { | ||
iNext = "bad"; | ||
continue; | ||
} | ||
iNext = i + 1; | ||
} | ||
} | ||
|
||
{ | ||
let iNext: string | number = ""; | ||
for ( | ||
let i = 0; | ||
i < 10; | ||
i = iNext // error | ||
~ | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
) { | ||
if (i == 5) { | ||
iNext = "bad"; | ||
continue; | ||
} | ||
iNext = i + 1; | ||
} | ||
} | ||
|
65 changes: 65 additions & 0 deletions
65
tests/baselines/reference/controlFlowForStatementContinueIntoIncrementor1.symbols
This file contains 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,65 @@ | ||
//// [tests/cases/compiler/controlFlowForStatementContinueIntoIncrementor1.ts] //// | ||
|
||
=== controlFlowForStatementContinueIntoIncrementor1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/60945 | ||
|
||
{ | ||
let iNext; | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 3, 5)) | ||
|
||
for ( | ||
let i = 0; | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 5, 7)) | ||
|
||
i < 10; | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 5, 7)) | ||
|
||
i = iNext // error | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 5, 7)) | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 3, 5)) | ||
|
||
) { | ||
if (i == 5) { | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 5, 7)) | ||
|
||
iNext = "bad"; | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 3, 5)) | ||
|
||
continue; | ||
} | ||
iNext = i + 1; | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 3, 5)) | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 5, 7)) | ||
} | ||
} | ||
|
||
{ | ||
let iNext: string | number = ""; | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 18, 5)) | ||
|
||
for ( | ||
let i = 0; | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 20, 7)) | ||
|
||
i < 10; | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 20, 7)) | ||
|
||
i = iNext // error | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 20, 7)) | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 18, 5)) | ||
|
||
) { | ||
if (i == 5) { | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 20, 7)) | ||
|
||
iNext = "bad"; | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 18, 5)) | ||
|
||
continue; | ||
} | ||
iNext = i + 1; | ||
>iNext : Symbol(iNext, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 18, 5)) | ||
>i : Symbol(i, Decl(controlFlowForStatementContinueIntoIncrementor1.ts, 20, 7)) | ||
} | ||
} | ||
|
129 changes: 129 additions & 0 deletions
129
tests/baselines/reference/controlFlowForStatementContinueIntoIncrementor1.types
This file contains 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,129 @@ | ||
//// [tests/cases/compiler/controlFlowForStatementContinueIntoIncrementor1.ts] //// | ||
|
||
=== controlFlowForStatementContinueIntoIncrementor1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/60945 | ||
|
||
{ | ||
let iNext; | ||
>iNext : any | ||
> : ^^^ | ||
|
||
for ( | ||
let i = 0; | ||
>i : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
i < 10; | ||
>i < 10 : boolean | ||
> : ^^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>10 : 10 | ||
> : ^^ | ||
|
||
i = iNext // error | ||
>i = iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
|
||
) { | ||
if (i == 5) { | ||
>i == 5 : boolean | ||
> : ^^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>5 : 5 | ||
> : ^ | ||
|
||
iNext = "bad"; | ||
>iNext = "bad" : "bad" | ||
> : ^^^^^ | ||
>iNext : any | ||
> : ^^^ | ||
>"bad" : "bad" | ||
> : ^^^^^ | ||
|
||
continue; | ||
} | ||
iNext = i + 1; | ||
>iNext = i + 1 : number | ||
> : ^^^^^^ | ||
>iNext : any | ||
> : ^^^ | ||
>i + 1 : number | ||
> : ^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>1 : 1 | ||
> : ^ | ||
} | ||
} | ||
|
||
{ | ||
let iNext: string | number = ""; | ||
>iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
>"" : "" | ||
> : ^^ | ||
|
||
for ( | ||
let i = 0; | ||
>i : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
i < 10; | ||
>i < 10 : boolean | ||
> : ^^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>10 : 10 | ||
> : ^^ | ||
|
||
i = iNext // error | ||
>i = iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
|
||
) { | ||
if (i == 5) { | ||
>i == 5 : boolean | ||
> : ^^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>5 : 5 | ||
> : ^ | ||
|
||
iNext = "bad"; | ||
>iNext = "bad" : "bad" | ||
> : ^^^^^ | ||
>iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
>"bad" : "bad" | ||
> : ^^^^^ | ||
|
||
continue; | ||
} | ||
iNext = i + 1; | ||
>iNext = i + 1 : number | ||
> : ^^^^^^ | ||
>iNext : string | number | ||
> : ^^^^^^^^^^^^^^^ | ||
>i + 1 : number | ||
> : ^^^^^^ | ||
>i : number | ||
> : ^^^^^^ | ||
>1 : 1 | ||
> : ^ | ||
} | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
tests/cases/compiler/controlFlowForStatementContinueIntoIncrementor1.ts
This file contains 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,34 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/60945 | ||
|
||
{ | ||
let iNext; | ||
for ( | ||
let i = 0; | ||
i < 10; | ||
i = iNext // error | ||
) { | ||
if (i == 5) { | ||
iNext = "bad"; | ||
continue; | ||
} | ||
iNext = i + 1; | ||
} | ||
} | ||
|
||
{ | ||
let iNext: string | number = ""; | ||
for ( | ||
let i = 0; | ||
i < 10; | ||
i = iNext // error | ||
) { | ||
if (i == 5) { | ||
iNext = "bad"; | ||
continue; | ||
} | ||
iNext = i + 1; | ||
} | ||
} |