From 10889a042c24ad8ce017450cb076404c0076ee0d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 16 Apr 2016 15:13:48 -0700 Subject: [PATCH] Accepting new baselines --- .../controlFlowIterationErrors.errors.txt | 72 +++++++++++++++ .../reference/controlFlowIterationErrors.js | 92 +++++++++++++++++++ .../reference/controlFlowWhileStatement.js | 57 ++++++++++++ .../controlFlowWhileStatement.symbols | 74 +++++++++++++++ .../reference/controlFlowWhileStatement.types | 88 ++++++++++++++++++ 5 files changed, 383 insertions(+) create mode 100644 tests/baselines/reference/controlFlowIterationErrors.errors.txt create mode 100644 tests/baselines/reference/controlFlowIterationErrors.js diff --git a/tests/baselines/reference/controlFlowIterationErrors.errors.txt b/tests/baselines/reference/controlFlowIterationErrors.errors.txt new file mode 100644 index 00000000000..748bf05dfb7 --- /dev/null +++ b/tests/baselines/reference/controlFlowIterationErrors.errors.txt @@ -0,0 +1,72 @@ +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(11,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(22,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(34,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (4 errors) ==== + let cond: boolean; + + function len(s: string) { + return s.length; + } + + function f1() { + let x: string | number | boolean; + x = ""; + while (cond) { + x = len(x); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + x; + } + x; + } + + function f2() { + let x: string | number | boolean; + x = ""; + while (cond) { + x; + x = len(x); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + } + x; + } + + declare function foo(x: string): number; + declare function foo(x: number): string; + + function g1() { + let x: string | number | boolean; + x = ""; + while (cond) { + x = foo(x); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + x; + } + x; + } + + function g2() { + let x: string | number | boolean; + x = ""; + while (cond) { + x; + x = foo(x); + ~ +!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } + x; + } + \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowIterationErrors.js b/tests/baselines/reference/controlFlowIterationErrors.js new file mode 100644 index 00000000000..6c4a9a0b7e0 --- /dev/null +++ b/tests/baselines/reference/controlFlowIterationErrors.js @@ -0,0 +1,92 @@ +//// [controlFlowIterationErrors.ts] +let cond: boolean; + +function len(s: string) { + return s.length; +} + +function f1() { + let x: string | number | boolean; + x = ""; + while (cond) { + x = len(x); + x; + } + x; +} + +function f2() { + let x: string | number | boolean; + x = ""; + while (cond) { + x; + x = len(x); + } + x; +} + +declare function foo(x: string): number; +declare function foo(x: number): string; + +function g1() { + let x: string | number | boolean; + x = ""; + while (cond) { + x = foo(x); + x; + } + x; +} + +function g2() { + let x: string | number | boolean; + x = ""; + while (cond) { + x; + x = foo(x); + } + x; +} + + +//// [controlFlowIterationErrors.js] +var cond; +function len(s) { + return s.length; +} +function f1() { + var x; + x = ""; + while (cond) { + x = len(x); + x; + } + x; +} +function f2() { + var x; + x = ""; + while (cond) { + x; + x = len(x); + } + x; +} +function g1() { + var x; + x = ""; + while (cond) { + x = foo(x); + x; + } + x; +} +function g2() { + var x; + x = ""; + while (cond) { + x; + x = foo(x); + } + x; +} diff --git a/tests/baselines/reference/controlFlowWhileStatement.js b/tests/baselines/reference/controlFlowWhileStatement.js index 2dfb716f7cc..d9faf9bd0ea 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.js +++ b/tests/baselines/reference/controlFlowWhileStatement.js @@ -76,6 +76,35 @@ function g() { } x; // number } +function h1() { + let x: string | number | boolean; + x = ""; + while (x > 1) { + x; // string | number + x = 1; + x; // number + } + x; // string | number +} +declare function len(s: string | number): number; +function h2() { + let x: string | number | boolean; + x = ""; + while (cond) { + x = len(x); + x; // number + } + x; // string | number +} +function h3() { + let x: string | number | boolean; + x = ""; + while (cond) { + x; // string | number + x = len(x); + } + x; // string | number +} //// [controlFlowWhileStatement.js] @@ -157,3 +186,31 @@ function g() { } x; // number } +function h1() { + var x; + x = ""; + while (x > 1) { + x; // string | number + x = 1; + x; // number + } + x; // string | number +} +function h2() { + var x; + x = ""; + while (cond) { + x = len(x); + x; // number + } + x; // string | number +} +function h3() { + var x; + x = ""; + while (cond) { + x; // string | number + x = len(x); + } + x; // string | number +} diff --git a/tests/baselines/reference/controlFlowWhileStatement.symbols b/tests/baselines/reference/controlFlowWhileStatement.symbols index 01af3654f3c..3b4def93b45 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.symbols +++ b/tests/baselines/reference/controlFlowWhileStatement.symbols @@ -180,4 +180,78 @@ function g() { x; // number >x : Symbol(x, Decl(controlFlowWhileStatement.ts, 62, 7)) } +function h1() { +>h1 : Symbol(h1, Decl(controlFlowWhileStatement.ts, 76, 1)) + + let x: string | number | boolean; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) + + x = ""; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) + + while (x > 1) { +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) + + x; // string | number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) + + x = 1; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) + + x; // number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) + } + x; // string | number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 78, 7)) +} +declare function len(s: string | number): number; +>len : Symbol(len, Decl(controlFlowWhileStatement.ts, 86, 1)) +>s : Symbol(s, Decl(controlFlowWhileStatement.ts, 87, 21)) + +function h2() { +>h2 : Symbol(h2, Decl(controlFlowWhileStatement.ts, 87, 49)) + + let x: string | number | boolean; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 89, 7)) + + x = ""; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 89, 7)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + x = len(x); +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 89, 7)) +>len : Symbol(len, Decl(controlFlowWhileStatement.ts, 86, 1)) +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 89, 7)) + + x; // number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 89, 7)) + } + x; // string | number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 89, 7)) +} +function h3() { +>h3 : Symbol(h3, Decl(controlFlowWhileStatement.ts, 96, 1)) + + let x: string | number | boolean; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) + + x = ""; +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWhileStatement.ts, 0, 3)) + + x; // string | number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) + + x = len(x); +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) +>len : Symbol(len, Decl(controlFlowWhileStatement.ts, 86, 1)) +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) + } + x; // string | number +>x : Symbol(x, Decl(controlFlowWhileStatement.ts, 98, 7)) +} diff --git a/tests/baselines/reference/controlFlowWhileStatement.types b/tests/baselines/reference/controlFlowWhileStatement.types index 3658a20897a..a17c084228b 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.types +++ b/tests/baselines/reference/controlFlowWhileStatement.types @@ -219,4 +219,92 @@ function g() { x; // number >x : number } +function h1() { +>h1 : () => void + + let x: string | number | boolean; +>x : string | number | boolean + + x = ""; +>x = "" : string +>x : string | number | boolean +>"" : string + + while (x > 1) { +>x > 1 : boolean +>x : string | number +>1 : number + + x; // string | number +>x : string | number + + x = 1; +>x = 1 : number +>x : string | number | boolean +>1 : number + + x; // number +>x : number + } + x; // string | number +>x : string | number +} +declare function len(s: string | number): number; +>len : (s: string | number) => number +>s : string | number + +function h2() { +>h2 : () => void + + let x: string | number | boolean; +>x : string | number | boolean + + x = ""; +>x = "" : string +>x : string | number | boolean +>"" : string + + while (cond) { +>cond : boolean + + x = len(x); +>x = len(x) : number +>x : string | number | boolean +>len(x) : number +>len : (s: string | number) => number +>x : string | number + + x; // number +>x : number + } + x; // string | number +>x : string | number +} +function h3() { +>h3 : () => void + + let x: string | number | boolean; +>x : string | number | boolean + + x = ""; +>x = "" : string +>x : string | number | boolean +>"" : string + + while (cond) { +>cond : boolean + + x; // string | number +>x : string | number + + x = len(x); +>x = len(x) : number +>x : string | number | boolean +>len(x) : number +>len : (s: string | number) => number +>x : string | number + } + x; // string | number +>x : string | number +}