From 24a108936f4941156147f3283f996f9e2fed972d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 22:27:57 -0500 Subject: [PATCH 1/7] Added tests. --- .../commaOperator/contextuallyTypeCommaOperator01.ts | 3 +++ .../commaOperator/contextuallyTypeCommaOperator02.ts | 6 ++++++ .../logicalAnd/contextuallyTypeLogicalAnd01.ts | 4 ++++ .../logicalAnd/contextuallyTypeLogicalAnd02.ts | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts create mode 100644 tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts create mode 100644 tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts create mode 100644 tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts diff --git a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts new file mode 100644 index 0000000000..f5d8326611 --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts @@ -0,0 +1,3 @@ +let x: (a: string) => string; + +x = (100, a => a); \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts new file mode 100644 index 0000000000..bd38c61677 --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts @@ -0,0 +1,6 @@ +let x: (a: string) => string; + +x = (100, a => { + const b: number = a; + return b; +}); \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts new file mode 100644 index 0000000000..2cc3d8fde2 --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts @@ -0,0 +1,4 @@ +let x: (a: string) => string; +let y = true; + +x = y && (a => a); \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts new file mode 100644 index 0000000000..fbd196e7b6 --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts @@ -0,0 +1,7 @@ +let x: (a: string) => string; +let y = true; + +x = y && (a => { + const b: number = a; + return b; +}); \ No newline at end of file From 4484ca062e6f8d7e05440dbafb59719ef3c7b31f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 22:39:47 -0500 Subject: [PATCH 2/7] Accepted baselines. --- .../contextuallyTypeCommaOperator01.js | 8 ++++++++ .../contextuallyTypeCommaOperator01.symbols | 10 ++++++++++ .../contextuallyTypeCommaOperator01.types | 15 +++++++++++++++ ...contextuallyTypeCommaOperator02.errors.txt | 14 ++++++++++++++ .../contextuallyTypeCommaOperator02.js | 14 ++++++++++++++ .../reference/contextuallyTypeLogicalAnd01.js | 10 ++++++++++ .../contextuallyTypeLogicalAnd01.symbols | 14 ++++++++++++++ .../contextuallyTypeLogicalAnd01.types | 19 +++++++++++++++++++ .../contextuallyTypeLogicalAnd02.errors.txt | 15 +++++++++++++++ .../reference/contextuallyTypeLogicalAnd02.js | 16 ++++++++++++++++ 10 files changed, 135 insertions(+) create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator01.js create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator01.symbols create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator01.types create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator02.js create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd01.js create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd01.types create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd02.js diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator01.js b/tests/baselines/reference/contextuallyTypeCommaOperator01.js new file mode 100644 index 0000000000..f8a9dbe7f8 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator01.js @@ -0,0 +1,8 @@ +//// [contextuallyTypeCommaOperator01.ts] +let x: (a: string) => string; + +x = (100, a => a); + +//// [contextuallyTypeCommaOperator01.js] +var x; +x = (100, function (a) { return a; }); diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols b/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols new file mode 100644 index 0000000000..b3b9326ea8 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts === +let x: (a: string) => string; +>x : Symbol(x, Decl(contextuallyTypeCommaOperator01.ts, 0, 3)) +>a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 0, 8)) + +x = (100, a => a); +>x : Symbol(x, Decl(contextuallyTypeCommaOperator01.ts, 0, 3)) +>a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 2, 9)) +>a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 2, 9)) + diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator01.types b/tests/baselines/reference/contextuallyTypeCommaOperator01.types new file mode 100644 index 0000000000..35d5ba5af0 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator01.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts === +let x: (a: string) => string; +>x : (a: string) => string +>a : string + +x = (100, a => a); +>x = (100, a => a) : (a: any) => any +>x : (a: string) => string +>(100, a => a) : (a: any) => any +>100, a => a : (a: any) => any +>100 : number +>a => a : (a: any) => any +>a : any +>a : any + diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt b/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt new file mode 100644 index 0000000000..e95eaedeaf --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts(3,1): error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts (1 errors) ==== + let x: (a: string) => string; + + x = (100, a => { + ~ +!!! error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + const b: number = a; + return b; + }); \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator02.js b/tests/baselines/reference/contextuallyTypeCommaOperator02.js new file mode 100644 index 0000000000..1d97d7ccaa --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator02.js @@ -0,0 +1,14 @@ +//// [contextuallyTypeCommaOperator02.ts] +let x: (a: string) => string; + +x = (100, a => { + const b: number = a; + return b; +}); + +//// [contextuallyTypeCommaOperator02.js] +var x; +x = (100, function (a) { + var b = a; + return b; +}); diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd01.js b/tests/baselines/reference/contextuallyTypeLogicalAnd01.js new file mode 100644 index 0000000000..35b509f119 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd01.js @@ -0,0 +1,10 @@ +//// [contextuallyTypeLogicalAnd01.ts] +let x: (a: string) => string; +let y = true; + +x = y && (a => a); + +//// [contextuallyTypeLogicalAnd01.js] +var x; +var y = true; +x = y && (function (a) { return a; }); diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols b/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols new file mode 100644 index 0000000000..a16ba5cc39 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts === +let x: (a: string) => string; +>x : Symbol(x, Decl(contextuallyTypeLogicalAnd01.ts, 0, 3)) +>a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 0, 8)) + +let y = true; +>y : Symbol(y, Decl(contextuallyTypeLogicalAnd01.ts, 1, 3)) + +x = y && (a => a); +>x : Symbol(x, Decl(contextuallyTypeLogicalAnd01.ts, 0, 3)) +>y : Symbol(y, Decl(contextuallyTypeLogicalAnd01.ts, 1, 3)) +>a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 3, 10)) +>a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 3, 10)) + diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd01.types b/tests/baselines/reference/contextuallyTypeLogicalAnd01.types new file mode 100644 index 0000000000..92f70dcc73 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd01.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts === +let x: (a: string) => string; +>x : (a: string) => string +>a : string + +let y = true; +>y : boolean +>true : boolean + +x = y && (a => a); +>x = y && (a => a) : (a: any) => any +>x : (a: string) => string +>y && (a => a) : (a: any) => any +>y : boolean +>(a => a) : (a: any) => any +>a => a : (a: any) => any +>a : any +>a : any + diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt b/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt new file mode 100644 index 0000000000..3d2cd6d065 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts(4,1): error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts (1 errors) ==== + let x: (a: string) => string; + let y = true; + + x = y && (a => { + ~ +!!! error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + const b: number = a; + return b; + }); \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd02.js b/tests/baselines/reference/contextuallyTypeLogicalAnd02.js new file mode 100644 index 0000000000..11ec0aa03a --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd02.js @@ -0,0 +1,16 @@ +//// [contextuallyTypeLogicalAnd02.ts] +let x: (a: string) => string; +let y = true; + +x = y && (a => { + const b: number = a; + return b; +}); + +//// [contextuallyTypeLogicalAnd02.js] +var x; +var y = true; +x = y && (function (a) { + var b = a; + return b; +}); From 06bff434ccc6c981b4a2c02f057e535d520a0636 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 22:48:53 -0500 Subject: [PATCH 3/7] Added 'noImplicitAny' to tests. --- .../commaOperator/contextuallyTypeCommaOperator01.ts | 2 ++ .../commaOperator/contextuallyTypeCommaOperator02.ts | 2 ++ .../contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts | 2 ++ .../contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts | 2 ++ 4 files changed, 8 insertions(+) diff --git a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts index f5d8326611..167369a020 100644 --- a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts +++ b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts @@ -1,3 +1,5 @@ +// @noImplicitAny: true + let x: (a: string) => string; x = (100, a => a); \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts index bd38c61677..11e743b583 100644 --- a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts +++ b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts @@ -1,3 +1,5 @@ +// @noImplicitAny: true + let x: (a: string) => string; x = (100, a => { diff --git a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts index 2cc3d8fde2..30e46429fa 100644 --- a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts +++ b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts @@ -1,3 +1,5 @@ +// @noImplicitAny: true + let x: (a: string) => string; let y = true; diff --git a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts index fbd196e7b6..26e58ae49e 100644 --- a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts +++ b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts @@ -1,3 +1,5 @@ +// @noImplicitAny: true + let x: (a: string) => string; let y = true; From 5ab5cfd2fd444cf42cc1c56f8b96519644191385 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 22:54:37 -0500 Subject: [PATCH 4/7] Contextually type the RHS of logical 'and' and comma expressions. --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2e798659d..fb4af5d729 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7362,6 +7362,12 @@ namespace ts { } return type; } + else if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.CommaToken) { + if (node === binaryExpression.right) { + return getContextualType(binaryExpression); + } + } + return undefined; } From b0576cdf8e1875d87a499e4bdb36fef2a5659aef Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 22:55:05 -0500 Subject: [PATCH 5/7] Accepted baselines. --- .../reference/contextuallyTypeCommaOperator01.js | 1 + .../contextuallyTypeCommaOperator01.symbols | 11 ++++++----- .../contextuallyTypeCommaOperator01.types | 13 +++++++------ .../contextuallyTypeCommaOperator02.errors.txt | 10 +++++++--- .../reference/contextuallyTypeCommaOperator02.js | 1 + .../reference/contextuallyTypeLogicalAnd01.js | 1 + .../contextuallyTypeLogicalAnd01.symbols | 15 ++++++++------- .../reference/contextuallyTypeLogicalAnd01.types | 13 +++++++------ .../contextuallyTypeLogicalAnd02.errors.txt | 10 +++++++--- .../reference/contextuallyTypeLogicalAnd02.js | 1 + 10 files changed, 46 insertions(+), 30 deletions(-) diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator01.js b/tests/baselines/reference/contextuallyTypeCommaOperator01.js index f8a9dbe7f8..0da3ac9100 100644 --- a/tests/baselines/reference/contextuallyTypeCommaOperator01.js +++ b/tests/baselines/reference/contextuallyTypeCommaOperator01.js @@ -1,4 +1,5 @@ //// [contextuallyTypeCommaOperator01.ts] + let x: (a: string) => string; x = (100, a => a); diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols b/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols index b3b9326ea8..c07fd28ae7 100644 --- a/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols +++ b/tests/baselines/reference/contextuallyTypeCommaOperator01.symbols @@ -1,10 +1,11 @@ === tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts === + let x: (a: string) => string; ->x : Symbol(x, Decl(contextuallyTypeCommaOperator01.ts, 0, 3)) ->a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 0, 8)) +>x : Symbol(x, Decl(contextuallyTypeCommaOperator01.ts, 1, 3)) +>a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 1, 8)) x = (100, a => a); ->x : Symbol(x, Decl(contextuallyTypeCommaOperator01.ts, 0, 3)) ->a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 2, 9)) ->a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 2, 9)) +>x : Symbol(x, Decl(contextuallyTypeCommaOperator01.ts, 1, 3)) +>a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 3, 9)) +>a : Symbol(a, Decl(contextuallyTypeCommaOperator01.ts, 3, 9)) diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator01.types b/tests/baselines/reference/contextuallyTypeCommaOperator01.types index 35d5ba5af0..c3b7b700d6 100644 --- a/tests/baselines/reference/contextuallyTypeCommaOperator01.types +++ b/tests/baselines/reference/contextuallyTypeCommaOperator01.types @@ -1,15 +1,16 @@ === tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator01.ts === + let x: (a: string) => string; >x : (a: string) => string >a : string x = (100, a => a); ->x = (100, a => a) : (a: any) => any +>x = (100, a => a) : (a: string) => string >x : (a: string) => string ->(100, a => a) : (a: any) => any ->100, a => a : (a: any) => any +>(100, a => a) : (a: string) => string +>100, a => a : (a: string) => string >100 : number ->a => a : (a: any) => any ->a : any ->a : any +>a => a : (a: string) => string +>a : string +>a : string diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt b/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt index e95eaedeaf..3214f7e502 100644 --- a/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt +++ b/tests/baselines/reference/contextuallyTypeCommaOperator02.errors.txt @@ -1,14 +1,18 @@ -tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts(3,1): error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. +tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts(4,1): error TS2322: Type '(a: string) => number' is not assignable to type '(a: string) => string'. Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts(5,11): error TS2322: Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts (1 errors) ==== +==== tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator02.ts (2 errors) ==== + let x: (a: string) => string; x = (100, a => { ~ -!!! error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. +!!! error TS2322: Type '(a: string) => number' is not assignable to type '(a: string) => string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. const b: number = a; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. return b; }); \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator02.js b/tests/baselines/reference/contextuallyTypeCommaOperator02.js index 1d97d7ccaa..0f8d67dd0e 100644 --- a/tests/baselines/reference/contextuallyTypeCommaOperator02.js +++ b/tests/baselines/reference/contextuallyTypeCommaOperator02.js @@ -1,4 +1,5 @@ //// [contextuallyTypeCommaOperator02.ts] + let x: (a: string) => string; x = (100, a => { diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd01.js b/tests/baselines/reference/contextuallyTypeLogicalAnd01.js index 35b509f119..b8b1f0d1e0 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd01.js +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd01.js @@ -1,4 +1,5 @@ //// [contextuallyTypeLogicalAnd01.ts] + let x: (a: string) => string; let y = true; diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols b/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols index a16ba5cc39..4d69b43e66 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd01.symbols @@ -1,14 +1,15 @@ === tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts === + let x: (a: string) => string; ->x : Symbol(x, Decl(contextuallyTypeLogicalAnd01.ts, 0, 3)) ->a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 0, 8)) +>x : Symbol(x, Decl(contextuallyTypeLogicalAnd01.ts, 1, 3)) +>a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 1, 8)) let y = true; ->y : Symbol(y, Decl(contextuallyTypeLogicalAnd01.ts, 1, 3)) +>y : Symbol(y, Decl(contextuallyTypeLogicalAnd01.ts, 2, 3)) x = y && (a => a); ->x : Symbol(x, Decl(contextuallyTypeLogicalAnd01.ts, 0, 3)) ->y : Symbol(y, Decl(contextuallyTypeLogicalAnd01.ts, 1, 3)) ->a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 3, 10)) ->a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 3, 10)) +>x : Symbol(x, Decl(contextuallyTypeLogicalAnd01.ts, 1, 3)) +>y : Symbol(y, Decl(contextuallyTypeLogicalAnd01.ts, 2, 3)) +>a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 4, 10)) +>a : Symbol(a, Decl(contextuallyTypeLogicalAnd01.ts, 4, 10)) diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd01.types b/tests/baselines/reference/contextuallyTypeLogicalAnd01.types index 92f70dcc73..a405888c8a 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd01.types +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd01.types @@ -1,4 +1,5 @@ === tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd01.ts === + let x: (a: string) => string; >x : (a: string) => string >a : string @@ -8,12 +9,12 @@ let y = true; >true : boolean x = y && (a => a); ->x = y && (a => a) : (a: any) => any +>x = y && (a => a) : (a: string) => string >x : (a: string) => string ->y && (a => a) : (a: any) => any +>y && (a => a) : (a: string) => string >y : boolean ->(a => a) : (a: any) => any ->a => a : (a: any) => any ->a : any ->a : any +>(a => a) : (a: string) => string +>a => a : (a: string) => string +>a : string +>a : string diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt b/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt index 3d2cd6d065..7452d333d8 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd02.errors.txt @@ -1,15 +1,19 @@ -tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts(4,1): error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. +tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts(5,1): error TS2322: Type '(a: string) => number' is not assignable to type '(a: string) => string'. Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts(6,11): error TS2322: Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts (1 errors) ==== +==== tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd02.ts (2 errors) ==== + let x: (a: string) => string; let y = true; x = y && (a => { ~ -!!! error TS2322: Type '(a: any) => number' is not assignable to type '(a: string) => string'. +!!! error TS2322: Type '(a: string) => number' is not assignable to type '(a: string) => string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. const b: number = a; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. return b; }); \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd02.js b/tests/baselines/reference/contextuallyTypeLogicalAnd02.js index 11ec0aa03a..6dc1fa5b26 100644 --- a/tests/baselines/reference/contextuallyTypeLogicalAnd02.js +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd02.js @@ -1,4 +1,5 @@ //// [contextuallyTypeLogicalAnd02.ts] + let x: (a: string) => string; let y = true; From 5323fa67830934ed3011a332e81761599be1e7f5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 22:58:49 -0500 Subject: [PATCH 6/7] Added tests for LHS expressions. --- .../commaOperator/contextuallyTypeCommaOperator03.ts | 5 +++++ .../logicalAnd/contextuallyTypeLogicalAnd03.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator03.ts create mode 100644 tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd03.ts diff --git a/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator03.ts b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator03.ts new file mode 100644 index 0000000000..321eb99d15 --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator03.ts @@ -0,0 +1,5 @@ +// @noImplicitAny: true + +let x: (a: string) => string; + +x = (a => a, b => b); \ No newline at end of file diff --git a/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd03.ts b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd03.ts new file mode 100644 index 0000000000..1fba96c048 --- /dev/null +++ b/tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd03.ts @@ -0,0 +1,6 @@ +// @noImplicitAny: true + +let x: (a: string) => string; +let y = true; + +x = (a => a) && (b => b); \ No newline at end of file From 7ce819f4c7d424fb0346fc56890d42a0261d5095 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 4 Jan 2016 23:02:11 -0500 Subject: [PATCH 7/7] Accepted baselines. --- .../contextuallyTypeCommaOperator03.errors.txt | 10 ++++++++++ .../reference/contextuallyTypeCommaOperator03.js | 9 +++++++++ .../reference/contextuallyTypeLogicalAnd03.errors.txt | 11 +++++++++++ .../reference/contextuallyTypeLogicalAnd03.js | 11 +++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator03.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypeCommaOperator03.js create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypeLogicalAnd03.js diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator03.errors.txt b/tests/baselines/reference/contextuallyTypeCommaOperator03.errors.txt new file mode 100644 index 0000000000..715b7cf70e --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator03.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator03.ts(4,6): error TS7006: Parameter 'a' implicitly has an 'any' type. + + +==== tests/cases/conformance/types/contextualTypes/commaOperator/contextuallyTypeCommaOperator03.ts (1 errors) ==== + + let x: (a: string) => string; + + x = (a => a, b => b); + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeCommaOperator03.js b/tests/baselines/reference/contextuallyTypeCommaOperator03.js new file mode 100644 index 0000000000..c4754f28c4 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeCommaOperator03.js @@ -0,0 +1,9 @@ +//// [contextuallyTypeCommaOperator03.ts] + +let x: (a: string) => string; + +x = (a => a, b => b); + +//// [contextuallyTypeCommaOperator03.js] +var x; +x = (function (a) { return a; }, function (b) { return b; }); diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt new file mode 100644 index 0000000000..1430be0042 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd03.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd03.ts(5,6): error TS7006: Parameter 'a' implicitly has an 'any' type. + + +==== tests/cases/conformance/types/contextualTypes/logicalAnd/contextuallyTypeLogicalAnd03.ts (1 errors) ==== + + let x: (a: string) => string; + let y = true; + + x = (a => a) && (b => b); + ~ +!!! error TS7006: Parameter 'a' implicitly has an 'any' type. \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypeLogicalAnd03.js b/tests/baselines/reference/contextuallyTypeLogicalAnd03.js new file mode 100644 index 0000000000..cbf1b3a319 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypeLogicalAnd03.js @@ -0,0 +1,11 @@ +//// [contextuallyTypeLogicalAnd03.ts] + +let x: (a: string) => string; +let y = true; + +x = (a => a) && (b => b); + +//// [contextuallyTypeLogicalAnd03.js] +var x; +var y = true; +x = (function (a) { return a; }) && (function (b) { return b; });