-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11432 from Microsoft/controlFlowArrays
Control flow analysis for array construction
- Loading branch information
Showing
20 changed files
with
2,234 additions
and
102 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
105 changes: 105 additions & 0 deletions
105
tests/baselines/reference/controlFlowArrayErrors.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,105 @@ | ||
tests/cases/compiler/controlFlowArrayErrors.ts(5,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(6,13): error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(12,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(14,13): error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(20,9): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(23,9): error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(30,12): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(35,12): error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(49,5): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((...items: (string | number)[]) => number) | ((...items: boolean[]) => number)' has no compatible call signatures. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(57,12): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(61,11): error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
tests/cases/compiler/controlFlowArrayErrors.ts(64,9): error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
|
||
|
||
==== tests/cases/compiler/controlFlowArrayErrors.ts (12 errors) ==== | ||
|
||
declare function cond(): boolean; | ||
|
||
function f1() { | ||
let x = []; // Implicit any[] error in some locations | ||
~ | ||
!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
let y = x; // Implicit any[] error | ||
~ | ||
!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
x.push(5); | ||
let z = x; | ||
} | ||
|
||
function f2() { | ||
let x; // Implicit any[] error in some locations | ||
~ | ||
!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
x = []; | ||
let y = x; // Implicit any[] error | ||
~ | ||
!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
x.push(5); | ||
let z = x; | ||
} | ||
|
||
function f3() { | ||
let x = []; // Implicit any[] error in some locations | ||
~ | ||
!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
x.push(5); | ||
function g() { | ||
x; // Implicit any[] error | ||
~ | ||
!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
} | ||
} | ||
|
||
function f4() { | ||
let x; | ||
x = [5, "hello"]; // Non-evolving array | ||
x.push(true); // Error | ||
~~~~ | ||
!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. | ||
} | ||
|
||
function f5() { | ||
let x = [5, "hello"]; // Non-evolving array | ||
x.push(true); // Error | ||
~~~~ | ||
!!! error TS2345: Argument of type 'true' is not assignable to parameter of type 'string | number'. | ||
} | ||
|
||
function f6() { | ||
let x; | ||
if (cond()) { | ||
x = []; | ||
x.push(5); | ||
x.push("hello"); | ||
} | ||
else { | ||
x = [true]; // Non-evolving array | ||
} | ||
x; // boolean[] | (string | number)[] | ||
x.push(99); // Error | ||
~~~~~~~~~~ | ||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((...items: (string | number)[]) => number) | ((...items: boolean[]) => number)' has no compatible call signatures. | ||
} | ||
|
||
function f7() { | ||
let x = []; // x has evolving array value | ||
x.push(5); | ||
let y = x; // y has non-evolving array value | ||
x.push("hello"); // Ok | ||
y.push("hello"); // Error | ||
~~~~~~~ | ||
!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. | ||
} | ||
|
||
function f8() { | ||
const x = []; // Implicit any[] error in some locations | ||
~ | ||
!!! error TS7034: Variable 'x' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
x.push(5); | ||
function g() { | ||
x; // Implicit any[] error | ||
~ | ||
!!! error TS7005: Variable 'x' implicitly has an 'any[]' type. | ||
} | ||
} |
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,125 @@ | ||
//// [controlFlowArrayErrors.ts] | ||
|
||
declare function cond(): boolean; | ||
|
||
function f1() { | ||
let x = []; // Implicit any[] error in some locations | ||
let y = x; // Implicit any[] error | ||
x.push(5); | ||
let z = x; | ||
} | ||
|
||
function f2() { | ||
let x; // Implicit any[] error in some locations | ||
x = []; | ||
let y = x; // Implicit any[] error | ||
x.push(5); | ||
let z = x; | ||
} | ||
|
||
function f3() { | ||
let x = []; // Implicit any[] error in some locations | ||
x.push(5); | ||
function g() { | ||
x; // Implicit any[] error | ||
} | ||
} | ||
|
||
function f4() { | ||
let x; | ||
x = [5, "hello"]; // Non-evolving array | ||
x.push(true); // Error | ||
} | ||
|
||
function f5() { | ||
let x = [5, "hello"]; // Non-evolving array | ||
x.push(true); // Error | ||
} | ||
|
||
function f6() { | ||
let x; | ||
if (cond()) { | ||
x = []; | ||
x.push(5); | ||
x.push("hello"); | ||
} | ||
else { | ||
x = [true]; // Non-evolving array | ||
} | ||
x; // boolean[] | (string | number)[] | ||
x.push(99); // Error | ||
} | ||
|
||
function f7() { | ||
let x = []; // x has evolving array value | ||
x.push(5); | ||
let y = x; // y has non-evolving array value | ||
x.push("hello"); // Ok | ||
y.push("hello"); // Error | ||
} | ||
|
||
function f8() { | ||
const x = []; // Implicit any[] error in some locations | ||
x.push(5); | ||
function g() { | ||
x; // Implicit any[] error | ||
} | ||
} | ||
|
||
//// [controlFlowArrayErrors.js] | ||
function f1() { | ||
var x = []; // Implicit any[] error in some locations | ||
var y = x; // Implicit any[] error | ||
x.push(5); | ||
var z = x; | ||
} | ||
function f2() { | ||
var x; // Implicit any[] error in some locations | ||
x = []; | ||
var y = x; // Implicit any[] error | ||
x.push(5); | ||
var z = x; | ||
} | ||
function f3() { | ||
var x = []; // Implicit any[] error in some locations | ||
x.push(5); | ||
function g() { | ||
x; // Implicit any[] error | ||
} | ||
} | ||
function f4() { | ||
var x; | ||
x = [5, "hello"]; // Non-evolving array | ||
x.push(true); // Error | ||
} | ||
function f5() { | ||
var x = [5, "hello"]; // Non-evolving array | ||
x.push(true); // Error | ||
} | ||
function f6() { | ||
var x; | ||
if (cond()) { | ||
x = []; | ||
x.push(5); | ||
x.push("hello"); | ||
} | ||
else { | ||
x = [true]; // Non-evolving array | ||
} | ||
x; // boolean[] | (string | number)[] | ||
x.push(99); // Error | ||
} | ||
function f7() { | ||
var x = []; // x has evolving array value | ||
x.push(5); | ||
var y = x; // y has non-evolving array value | ||
x.push("hello"); // Ok | ||
y.push("hello"); // Error | ||
} | ||
function f8() { | ||
var x = []; // Implicit any[] error in some locations | ||
x.push(5); | ||
function g() { | ||
x; // Implicit any[] error | ||
} | ||
} |
Oops, something went wrong.