From 2f5af2e04b995873b89fb3cc8744fbdfa36a1a8f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 6 Oct 2016 17:02:33 -0700 Subject: [PATCH] Add additional test --- .../reference/controlFlowArrayErrors.errors.txt | 16 +++++++++++++++- .../reference/controlFlowArrayErrors.js | 15 +++++++++++++++ tests/cases/compiler/controlFlowArrayErrors.ts | 8 ++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/controlFlowArrayErrors.errors.txt b/tests/baselines/reference/controlFlowArrayErrors.errors.txt index 7475c273243..bc13de261e2 100644 --- a/tests/baselines/reference/controlFlowArrayErrors.errors.txt +++ b/tests/baselines/reference/controlFlowArrayErrors.errors.txt @@ -6,9 +6,11 @@ tests/cases/compiler/controlFlowArrayErrors.ts(30,12): error TS2345: Argument of 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 (8 errors) ==== +==== tests/cases/compiler/controlFlowArrayErrors.ts (10 errors) ==== declare function cond(): boolean; @@ -82,4 +84,16 @@ tests/cases/compiler/controlFlowArrayErrors.ts(57,12): error TS2345: Argument of 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. + } } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowArrayErrors.js b/tests/baselines/reference/controlFlowArrayErrors.js index c1589449334..538addc31c0 100644 --- a/tests/baselines/reference/controlFlowArrayErrors.js +++ b/tests/baselines/reference/controlFlowArrayErrors.js @@ -56,6 +56,14 @@ function f7() { 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] @@ -108,3 +116,10 @@ function f7() { 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 + } +} diff --git a/tests/cases/compiler/controlFlowArrayErrors.ts b/tests/cases/compiler/controlFlowArrayErrors.ts index 84da65c41dc..aab3a974cd8 100644 --- a/tests/cases/compiler/controlFlowArrayErrors.ts +++ b/tests/cases/compiler/controlFlowArrayErrors.ts @@ -56,4 +56,12 @@ function f7() { 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 + } } \ No newline at end of file