From d5f02813f01f31eb4b72cf2f2f7d7351cb5328b2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 8 Jan 2015 16:39:47 -0800 Subject: [PATCH 1/5] Added tests for contextual typing on parenthesized expressions, added case for tagged templates. --- .../parenthesizedContexualTyping1.js | 52 ++++ .../parenthesizedContexualTyping1.types | 289 ++++++++++++++++++ .../parenthesizedContexualTyping2.errors.txt | 86 ++++++ .../parenthesizedContexualTyping2.js | 126 ++++++++ .../parenthesizedContexualTyping3.js | 35 +++ .../parenthesizedContexualTyping3.types | 142 +++++++++ .../taggedTemplateContextualTyping1.js | 5 + .../taggedTemplateContextualTyping1.types | 9 + .../parenthesizedContexualTyping1.ts | 29 ++ .../parenthesizedContexualTyping2.ts | 35 +++ .../parenthesizedContexualTyping3.ts | 21 ++ .../taggedTemplateContextualTyping1.ts | 1 + 12 files changed, 830 insertions(+) create mode 100644 tests/baselines/reference/parenthesizedContexualTyping1.js create mode 100644 tests/baselines/reference/parenthesizedContexualTyping1.types create mode 100644 tests/baselines/reference/parenthesizedContexualTyping2.errors.txt create mode 100644 tests/baselines/reference/parenthesizedContexualTyping2.js create mode 100644 tests/baselines/reference/parenthesizedContexualTyping3.js create mode 100644 tests/baselines/reference/parenthesizedContexualTyping3.types create mode 100644 tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.js b/tests/baselines/reference/parenthesizedContexualTyping1.js new file mode 100644 index 0000000000000..2f1e9ff62fc18 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping1.js @@ -0,0 +1,52 @@ +//// [parenthesizedContexualTyping1.ts] + +function fun(g: (x: T) => T, x: T): T; +function fun(g: (x: T) => T, h: (y: T) => T, x: T): T; +function fun(g: (x: T) => T, x: T): T { + return g(x); +} + +var a = fun(x => x, 10); +var b = fun((x => x), 10); +var c = fun(((x => x)), 10); +var d = fun((((x => x))), 10); + +var e = fun(x => x, x => x, 10); +var f = fun((x => x), (x => x), 10); +var g = fun(((x => x)), ((x => x)), 10); +var h = fun((((x => x))), ((x => x)), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); +var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); + +var lambda1: (x: number) => number = x => x; +var lambda2: (x: number) => number = (x => x); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); + +//// [parenthesizedContexualTyping1.js] +function fun(g, x) { + return g(x); +} +var a = fun(function (x) { return x; }, 10); +var b = fun((function (x) { return x; }), 10); +var c = fun(((function (x) { return x; })), 10); +var d = fun((((function (x) { return x; }))), 10); +var e = fun(function (x) { return x; }, function (x) { return x; }, 10); +var f = fun((function (x) { return x; }), (function (x) { return x; }), 10); +var g = fun(((function (x) { return x; })), ((function (x) { return x; })), 10); +var h = fun((((function (x) { return x; }))), ((function (x) { return x; })), 10); +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? function (x) { return x; } : function (x) { return undefined; }), 10); +var j = fun((Math.random() < 0.5 ? (function (x) { return x; }) : (function (x) { return undefined; })), 10); +var k = fun((Math.random() < 0.5 ? (function (x) { return x; }) : (function (x) { return undefined; })), function (x) { return x; }, 10); +var l = fun(((Math.random() < 0.5 ? ((function (x) { return x; })) : ((function (x) { return undefined; })))), ((function (x) { return x; })), 10); +var lambda1 = function (x) { return x; }; +var lambda2 = (function (x) { return x; }); +var obj1 = { x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }; +var obj2 = ({ x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }); diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.types b/tests/baselines/reference/parenthesizedContexualTyping1.types new file mode 100644 index 0000000000000..c8685206c474f --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping1.types @@ -0,0 +1,289 @@ +=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts === + +function fun(g: (x: T) => T, x: T): T; +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function fun(g: (x: T) => T, h: (y: T) => T, x: T): T; +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>g : (x: T) => T +>x : T +>T : T +>T : T +>h : (y: T) => T +>y : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function fun(g: (x: T) => T, x: T): T { +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + + return g(x); +>g(x) : T +>g : (x: T) => T +>x : T +} + +var a = fun(x => x, 10); +>a : number +>fun(x => x, 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number + +var b = fun((x => x), 10); +>b : any +>fun((x => x), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var c = fun(((x => x)), 10); +>c : any +>fun(((x => x)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var d = fun((((x => x))), 10); +>d : any +>fun((((x => x))), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(((x => x))) : (x: any) => any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var e = fun(x => x, x => x, 10); +>e : number +>fun(x => x, x => x, 10) : number +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number +>x => x : (x: number) => number +>x : number +>x : number + +var f = fun((x => x), (x => x), 10); +>f : any +>fun((x => x), (x => x), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var g = fun(((x => x)), ((x => x)), 10); +>g : any +>fun(((x => x)), ((x => x)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var h = fun((((x => x))), ((x => x)), 10); +>h : any +>fun((((x => x))), ((x => x)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(((x => x))) : (x: any) => any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); +>i : any +>fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(Math.random() < 0.5 ? x => x : x => undefined) : (x: any) => any +>Math.random() < 0.5 ? x => x : x => undefined : (x: any) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>x => x : (x: any) => any +>x : any +>x : any +>x => undefined : (x: any) => any +>x : any +>undefined : undefined + +var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); +>j : any +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: any) => any +>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: any) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>(x => undefined) : (x: any) => any +>x => undefined : (x: any) => any +>x : any +>undefined : undefined + +var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); +>k : any +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: any) => any +>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: any) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>(x => undefined) : (x: any) => any +>x => undefined : (x: any) => any +>x : any +>undefined : undefined +>x => x : (x: any) => any +>x : any +>x : any + +var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); +>l : any +>fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any +>fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: any) => any +>(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: any) => any +>Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : (x: any) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>((x => undefined)) : (x: any) => any +>(x => undefined) : (x: any) => any +>x => undefined : (x: any) => any +>x : any +>undefined : undefined +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var lambda1: (x: number) => number = x => x; +>lambda1 : (x: number) => number +>x : number +>x => x : (x: number) => number +>x : number +>x : number + +var lambda2: (x: number) => number = (x => x); +>lambda2 : (x: number) => number +>x : number +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>x : (p: number) => string +>p : number +>y : (p: string) => number +>p : string + +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +>obj1 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); +>obj2 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: any) => any; y: (y: any) => any; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: any) => any; y: (y: any) => any; } +>x : (x: any) => any +>x => (x, undefined) : (x: any) => any +>x : any +>(x, undefined) : undefined +>x, undefined : undefined +>x : any +>undefined : undefined +>y : (y: any) => any +>y => (y, undefined) : (y: any) => any +>y : any +>(y, undefined) : undefined +>y, undefined : undefined +>y : any +>undefined : undefined + diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt new file mode 100644 index 0000000000000..236dfee0979b1 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt @@ -0,0 +1,86 @@ +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(15,21): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(16,22): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(17,23): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(20,21): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(20,64): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,22): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,67): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,23): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,69): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(25,43): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(26,44): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(27,44): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,46): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,114): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(30,45): error TS2349: Cannot invoke an expression whose type lacks a call signature. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(31,46): error TS2347: Untyped function calls may not accept type arguments. + + +==== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts (16 errors) ==== + // These tests ensure that in cases where it may *appear* that a value has a type, + // they actually are properly being contextually typed. The way we test this is + // that we invoke contextually typed arguments with type arguments. + // Since 'any' cannot be invoked with type arguments, we should get errors back. + + type FuncType = (x: (p: T) => T) => typeof x; + + function fun(f: FuncType, x: T): T; + function fun(f: FuncType, g: FuncType, x: T): T; + function fun(...rest: any[]): T { + return undefined; + } + + var a = fun(x => { x(undefined); return x; }, 10); + var b = fun((x => { x(undefined); return x; }), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var c = fun(((x => { x(undefined); return x; })), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var d = fun((((x => { x(undefined); return x; }))), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + + var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); + var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + + // Ternaries in parens + var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + + var lambda1: (x: number) => number = x => { x(undefined); return x; }; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + var lambda2: (x: number) => number = (x => { x(undefined); return x; }); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2347: Untyped function calls may not accept type arguments. + + type ObjType = { x: (p: number) => string; y: (p: string) => number }; + var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; + var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); \ No newline at end of file diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.js b/tests/baselines/reference/parenthesizedContexualTyping2.js new file mode 100644 index 0000000000000..724cbaba2b634 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping2.js @@ -0,0 +1,126 @@ +//// [parenthesizedContexualTyping2.ts] +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors back. + +type FuncType = (x: (p: T) => T) => typeof x; + +function fun(f: FuncType, x: T): T; +function fun(f: FuncType, g: FuncType, x: T): T; +function fun(...rest: any[]): T { + return undefined; +} + +var a = fun(x => { x(undefined); return x; }, 10); +var b = fun((x => { x(undefined); return x; }), 10); +var c = fun(((x => { x(undefined); return x; })), 10); +var d = fun((((x => { x(undefined); return x; }))), 10); + +var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); +var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); +var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); +var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); +var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); + +var lambda1: (x: number) => number = x => { x(undefined); return x; }; +var lambda2: (x: number) => number = (x => { x(undefined); return x; }); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); + +//// [parenthesizedContexualTyping2.js] +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors back. +function fun() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } + return undefined; +} +var a = fun(function (x) { + x(undefined); + return x; +}, 10); +var b = fun((function (x) { + x(undefined); + return x; +}), 10); +var c = fun(((function (x) { + x(undefined); + return x; +})), 10); +var d = fun((((function (x) { + x(undefined); + return x; +}))), 10); +var e = fun(function (x) { + x(undefined); + return x; +}, function (x) { + x(undefined); + return x; +}, 10); +var f = fun((function (x) { + x(undefined); + return x; +}), (function (x) { + x(undefined); + return x; +}), 10); +var g = fun(((function (x) { + x(undefined); + return x; +})), ((function (x) { + x(undefined); + return x; +})), 10); +var h = fun((((function (x) { + x(undefined); + return x; +}))), ((function (x) { + x(undefined); + return x; +})), 10); +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? function (x) { + x(undefined); + return x; +} : function (x) { return undefined; }), 10); +var j = fun((Math.random() < 0.5 ? (function (x) { + x(undefined); + return x; +}) : (function (x) { return undefined; })), 10); +var k = fun((Math.random() < 0.5 ? (function (x) { + x(undefined); + return x; +}) : (function (x) { return undefined; })), function (x) { + x(undefined); + return x; +}, 10); +var l = fun(((Math.random() < 0.5 ? ((function (x) { + x(undefined); + return x; +})) : ((function (x) { return undefined; })))), ((function (x) { + x(undefined); + return x; +})), 10); +var lambda1 = function (x) { + x(undefined); + return x; +}; +var lambda2 = (function (x) { + x(undefined); + return x; +}); +var obj1 = { x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }; +var obj2 = ({ x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } }); diff --git a/tests/baselines/reference/parenthesizedContexualTyping3.js b/tests/baselines/reference/parenthesizedContexualTyping3.js new file mode 100644 index 0000000000000..69784d14ce404 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping3.js @@ -0,0 +1,35 @@ +//// [parenthesizedContexualTyping3.ts] + +// Contextual typing for parenthesized substitution expressions in tagged templates. + +/** + * tempFun - Can't have fun for too long. + */ +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T { + return g(x); +} + +var a = tempFun `${ x => x } ${ 10 }` +var b = tempFun `${ (x => x) } ${ 10 }` +var c = tempFun `${ ((x => x)) } ${ 10 }` +var d = tempFun `${ x => x } ${ x => x } ${ 10 }` +var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` +var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` +var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` +var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` + +//// [parenthesizedContexualTyping3.js] +// Contextual typing for parenthesized substitution expressions in tagged templates. +function tempFun(tempStrs, g, x) { + return g(x); +} +var a = tempFun `${function (x) { return x; }} ${10}`; +var b = tempFun `${(function (x) { return x; })} ${10}`; +var c = tempFun `${((function (x) { return x; }))} ${10}`; +var d = tempFun `${function (x) { return x; }} ${function (x) { return x; }} ${10}`; +var e = tempFun `${function (x) { return x; }} ${(function (x) { return x; })} ${10}`; +var f = tempFun `${function (x) { return x; }} ${((function (x) { return x; }))} ${10}`; +var g = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${10}`; +var h = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${undefined}`; diff --git a/tests/baselines/reference/parenthesizedContexualTyping3.types b/tests/baselines/reference/parenthesizedContexualTyping3.types new file mode 100644 index 0000000000000..6f9f24ef90b12 --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping3.types @@ -0,0 +1,142 @@ +=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts === + +// Contextual typing for parenthesized substitution expressions in tagged templates. + +/** + * tempFun - Can't have fun for too long. + */ +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>tempStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>tempStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>g : (x: T) => T +>x : T +>T : T +>T : T +>h : (y: T) => T +>y : T +>T : T +>T : T +>x : T +>T : T +>T : T + +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T { +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>T : T +>tempStrs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray +>g : (x: T) => T +>x : T +>T : T +>T : T +>x : T +>T : T +>T : T + + return g(x); +>g(x) : T +>g : (x: T) => T +>x : T +} + +var a = tempFun `${ x => x } ${ 10 }` +>a : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number + +var b = tempFun `${ (x => x) } ${ 10 }` +>b : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var c = tempFun `${ ((x => x)) } ${ 10 }` +>c : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var d = tempFun `${ x => x } ${ x => x } ${ 10 }` +>d : number +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: number) => number +>x : number +>x : number +>x => x : (x: number) => number +>x : number +>x : number + +var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` +>e : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: any) => any +>x : any +>x : any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` +>f : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>x => x : (x: any) => any +>x : any +>x : any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` +>g : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>(((x => x))) : (x: any) => any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any + +var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` +>h : any +>tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>(((x => x))) : (x: any) => any +>((x => x)) : (x: any) => any +>(x => x) : (x: any) => any +>x => x : (x: any) => any +>x : any +>x : any +>undefined : undefined + diff --git a/tests/baselines/reference/taggedTemplateContextualTyping1.js b/tests/baselines/reference/taggedTemplateContextualTyping1.js index d631a718bf3f8..c1ae5c384e453 100644 --- a/tests/baselines/reference/taggedTemplateContextualTyping1.js +++ b/tests/baselines/reference/taggedTemplateContextualTyping1.js @@ -12,6 +12,7 @@ function tempTag1(...rest: any[]): T { // Otherwise, the arrow functions' parameters will be typed as 'any', // and it is an error to invoke an any-typed value with type arguments, // so this test will error. +tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }`; tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }`; @@ -25,6 +26,10 @@ function tempTag1(...rest) { // Otherwise, the arrow functions' parameters will be typed as 'any', // and it is an error to invoke an any-typed value with type arguments, // so this test will error. +tempTag1 `${function (x) { + x(undefined); + return x; +}}${10}`; tempTag1 `${function (x) { x(undefined); return x; diff --git a/tests/baselines/reference/taggedTemplateContextualTyping1.types b/tests/baselines/reference/taggedTemplateContextualTyping1.types index a87d5eaa7a4d5..a6432d34f8122 100644 --- a/tests/baselines/reference/taggedTemplateContextualTyping1.types +++ b/tests/baselines/reference/taggedTemplateContextualTyping1.types @@ -47,6 +47,15 @@ function tempTag1(...rest: any[]): T { // Otherwise, the arrow functions' parameters will be typed as 'any', // and it is an error to invoke an any-typed value with type arguments, // so this test will error. +tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; +>tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; >tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts new file mode 100644 index 0000000000000..49dfe75ccc60e --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts @@ -0,0 +1,29 @@ + +function fun(g: (x: T) => T, x: T): T; +function fun(g: (x: T) => T, h: (y: T) => T, x: T): T; +function fun(g: (x: T) => T, x: T): T { + return g(x); +} + +var a = fun(x => x, 10); +var b = fun((x => x), 10); +var c = fun(((x => x)), 10); +var d = fun((((x => x))), 10); + +var e = fun(x => x, x => x, 10); +var f = fun((x => x), (x => x), 10); +var g = fun(((x => x)), ((x => x)), 10); +var h = fun((((x => x))), ((x => x)), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); +var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); + +var lambda1: (x: number) => number = x => x; +var lambda2: (x: number) => number = (x => x); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts new file mode 100644 index 0000000000000..5d235bff348b8 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts @@ -0,0 +1,35 @@ +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors back. + +type FuncType = (x: (p: T) => T) => typeof x; + +function fun(f: FuncType, x: T): T; +function fun(f: FuncType, g: FuncType, x: T): T; +function fun(...rest: any[]): T { + return undefined; +} + +var a = fun(x => { x(undefined); return x; }, 10); +var b = fun((x => { x(undefined); return x; }), 10); +var c = fun(((x => { x(undefined); return x; })), 10); +var d = fun((((x => { x(undefined); return x; }))), 10); + +var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); +var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); +var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); +var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); +var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); +var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); +var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); + +var lambda1: (x: number) => number = x => { x(undefined); return x; }; +var lambda2: (x: number) => number = (x => { x(undefined); return x; }); + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts new file mode 100644 index 0000000000000..004617c3d819d --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts @@ -0,0 +1,21 @@ +// @target: ES6 + +// Contextual typing for parenthesized substitution expressions in tagged templates. + +/** + * tempFun - Can't have fun for too long. + */ +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; +function tempFun(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T { + return g(x); +} + +var a = tempFun `${ x => x } ${ 10 }` +var b = tempFun `${ (x => x) } ${ 10 }` +var c = tempFun `${ ((x => x)) } ${ 10 }` +var d = tempFun `${ x => x } ${ x => x } ${ 10 }` +var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` +var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` +var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` +var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts index c15d911ee5254..84562f788f3d8 100644 --- a/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts @@ -12,6 +12,7 @@ function tempTag1(...rest: any[]): T { // Otherwise, the arrow functions' parameters will be typed as 'any', // and it is an error to invoke an any-typed value with type arguments, // so this test will error. +tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }`; tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }`; From f5f4e28f4f6105292349b8a10f1f316ae889e528 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 8 Jan 2015 16:53:26 -0800 Subject: [PATCH 2/5] Fixed portion of test. --- .../parenthesizedContexualTyping2.errors.txt | 13 +++++-------- .../reference/parenthesizedContexualTyping2.js | 4 ++-- .../parenthesizedContexualTyping2.ts | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt index 236dfee0979b1..c651110071d36 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt +++ b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt @@ -12,11 +12,10 @@ tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTypin tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(27,44): error TS2347: Untyped function calls may not accept type arguments. tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,46): error TS2347: Untyped function calls may not accept type arguments. tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,114): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(30,45): error TS2349: Cannot invoke an expression whose type lacks a call signature. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(31,46): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(31,33): error TS2347: Untyped function calls may not accept type arguments. -==== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts (16 errors) ==== +==== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts (15 errors) ==== // These tests ensure that in cases where it may *appear* that a value has a type, // they actually are properly being contextually typed. The way we test this is // that we invoke contextually typed arguments with type arguments. @@ -74,11 +73,9 @@ tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTypin ~~~~~~~~~~~~~~~~~~~~ !!! error TS2347: Untyped function calls may not accept type arguments. - var lambda1: (x: number) => number = x => { x(undefined); return x; }; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. - var lambda2: (x: number) => number = (x => { x(undefined); return x; }); - ~~~~~~~~~~~~~~~~~~~~ + var lambda1: FuncType = x => { x(undefined); return x; }; + var lambda2: FuncType = (x => { x(undefined); return x; }); + ~~~~~~~~~~~~~~~~~~~~ !!! error TS2347: Untyped function calls may not accept type arguments. type ObjType = { x: (p: number) => string; y: (p: string) => number }; diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.js b/tests/baselines/reference/parenthesizedContexualTyping2.js index 724cbaba2b634..2ce2e35c90665 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.js +++ b/tests/baselines/reference/parenthesizedContexualTyping2.js @@ -28,8 +28,8 @@ var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); -var lambda1: (x: number) => number = x => { x(undefined); return x; }; -var lambda2: (x: number) => number = (x => { x(undefined); return x; }); +var lambda1: FuncType = x => { x(undefined); return x; }; +var lambda2: FuncType = (x => { x(undefined); return x; }); type ObjType = { x: (p: number) => string; y: (p: string) => number }; var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts index 5d235bff348b8..87f3dc6a5801d 100644 --- a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts @@ -27,8 +27,8 @@ var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); -var lambda1: (x: number) => number = x => { x(undefined); return x; }; -var lambda2: (x: number) => number = (x => { x(undefined); return x; }); +var lambda1: FuncType = x => { x(undefined); return x; }; +var lambda2: FuncType = (x => { x(undefined); return x; }); type ObjType = { x: (p: number) => string; y: (p: string) => number }; var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; From cd246992ed4de56d700de735a2c823bb9278bea0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 9 Jan 2015 14:19:24 -0800 Subject: [PATCH 3/5] Clarified comment in test. --- .../parenthesizedContexualTyping2.errors.txt | 31 ++++++++++--------- .../parenthesizedContexualTyping2.js | 6 ++-- .../parenthesizedContexualTyping2.ts | 3 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt index c651110071d36..e4a9f0df708b1 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt +++ b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt @@ -1,25 +1,26 @@ -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(15,21): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(16,22): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(17,23): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(20,21): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(20,64): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,22): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,67): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,23): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,69): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(25,43): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(26,44): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(16,21): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(17,22): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(18,23): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,21): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,64): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,22): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,67): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(23,23): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(23,69): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(26,43): error TS2347: Untyped function calls may not accept type arguments. tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(27,44): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,46): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,114): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(31,33): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,44): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(29,46): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(29,114): error TS2347: Untyped function calls may not accept type arguments. +tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(32,33): error TS2347: Untyped function calls may not accept type arguments. ==== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts (15 errors) ==== // These tests ensure that in cases where it may *appear* that a value has a type, // they actually are properly being contextually typed. The way we test this is // that we invoke contextually typed arguments with type arguments. - // Since 'any' cannot be invoked with type arguments, we should get errors back. + // Since 'any' cannot be invoked with type arguments, we should get errors + // back if contextual typing is not taking effect. type FuncType = (x: (p: T) => T) => typeof x; diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.js b/tests/baselines/reference/parenthesizedContexualTyping2.js index 2ce2e35c90665..d5e4e0ebe8f00 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.js +++ b/tests/baselines/reference/parenthesizedContexualTyping2.js @@ -2,7 +2,8 @@ // These tests ensure that in cases where it may *appear* that a value has a type, // they actually are properly being contextually typed. The way we test this is // that we invoke contextually typed arguments with type arguments. -// Since 'any' cannot be invoked with type arguments, we should get errors back. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. type FuncType = (x: (p: T) => T) => typeof x; @@ -39,7 +40,8 @@ var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); // These tests ensure that in cases where it may *appear* that a value has a type, // they actually are properly being contextually typed. The way we test this is // that we invoke contextually typed arguments with type arguments. -// Since 'any' cannot be invoked with type arguments, we should get errors back. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. function fun() { var rest = []; for (var _i = 0; _i < arguments.length; _i++) { diff --git a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts index 87f3dc6a5801d..15acbf3e134df 100644 --- a/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts +++ b/tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts @@ -1,7 +1,8 @@ // These tests ensure that in cases where it may *appear* that a value has a type, // they actually are properly being contextually typed. The way we test this is // that we invoke contextually typed arguments with type arguments. -// Since 'any' cannot be invoked with type arguments, we should get errors back. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. type FuncType = (x: (p: T) => T) => typeof x; From 22174a17c64319942f56da8d19ff97f3f14f8f54 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 9 Jan 2015 15:10:32 -0800 Subject: [PATCH 4/5] Contextually type parenthesized expressions. --- src/compiler/checker.ts | 4 + tests/baselines/reference/castTest.types | 24 +- ...lTypingWithFixedTypeParameters1.errors.txt | 12 +- ...alOrExpressionIsNotContextuallyTyped.types | 18 +- .../parenthesizedContexualTyping1.types | 224 +++++------ .../parenthesizedContexualTyping2.errors.txt | 84 ----- .../parenthesizedContexualTyping2.types | 350 ++++++++++++++++++ .../parenthesizedContexualTyping3.types | 78 ++-- tests/cases/fourslash/assertContextualType.ts | 2 +- tests/cases/fourslash/contextualTyping.ts | 26 +- 10 files changed, 550 insertions(+), 272 deletions(-) delete mode 100644 tests/baselines/reference/parenthesizedContexualTyping2.errors.txt create mode 100644 tests/baselines/reference/parenthesizedContexualTyping2.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 21633d97a3ec4..0cf6413370fc2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3337,6 +3337,8 @@ module ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return isContextSensitiveFunctionLikeDeclaration(node); + case SyntaxKind.ParenthesizedExpression: + return isContextSensitive((node).expression); } return false; @@ -5226,6 +5228,8 @@ module ts { case SyntaxKind.TemplateSpan: Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression); return getContextualTypeForSubstitutionExpression(parent.parent, node); + case SyntaxKind.ParenthesizedExpression: + return getContextualType(parent); } return undefined; } diff --git a/tests/baselines/reference/castTest.types b/tests/baselines/reference/castTest.types index 501ff5a3cbed9..8250bec362def 100644 --- a/tests/baselines/reference/castTest.types +++ b/tests/baselines/reference/castTest.types @@ -65,8 +65,8 @@ var p_cast = ({ >p_cast : Point > ({ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }}) : Point >Point : Point ->({ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }}) : { x: number; y: number; add: (dx: any, dy: any) => Point; mult: (p: any) => any; } ->{ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }} : { x: number; y: number; add: (dx: any, dy: any) => Point; mult: (p: any) => any; } +>({ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }}) : { x: number; y: number; add: (dx: number, dy: number) => Point; mult: (p: Point) => Point; } +>{ x: 0, y: 0, add: function(dx, dy) { return new Point(this.x + dx, this.y + dy); }, mult: function(p) { return p; }} : { x: number; y: number; add: (dx: number, dy: number) => Point; mult: (p: Point) => Point; } x: 0, >x : number @@ -75,10 +75,10 @@ var p_cast = ({ >y : number add: function(dx, dy) { ->add : (dx: any, dy: any) => Point ->function(dx, dy) { return new Point(this.x + dx, this.y + dy); } : (dx: any, dy: any) => Point ->dx : any ->dy : any +>add : (dx: number, dy: number) => Point +>function(dx, dy) { return new Point(this.x + dx, this.y + dy); } : (dx: number, dy: number) => Point +>dx : number +>dy : number return new Point(this.x + dx, this.y + dy); >new Point(this.x + dx, this.y + dy) : Point @@ -87,19 +87,19 @@ var p_cast = ({ >this.x : any >this : any >x : any ->dx : any +>dx : number >this.y + dy : any >this.y : any >this : any >y : any ->dy : any +>dy : number }, mult: function(p) { return p; } ->mult : (p: any) => any ->function(p) { return p; } : (p: any) => any ->p : any ->p : any +>mult : (p: Point) => Point +>function(p) { return p; } : (p: Point) => Point +>p : Point +>p : Point }) diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt index 972b4bb918887..adfb1c68b7a6d 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt @@ -1,9 +1,17 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'T'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,32): error TS2339: Property 'foo' does not exist on type 'T'. -==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ==== +==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (3 errors) ==== var f10: (x: T, b: () => (a: T) => void, y: T) => T; f10('', () => a => a.foo, ''); // a is string ~~~ !!! error TS2339: Property 'foo' does not exist on type 'string'. - var r9 = f10('', () => (a => a.foo), 1); // error \ No newline at end of file + var r9 = f10('', () => (a => a.foo), 1); // error + ~~~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'T'. + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'T'. \ No newline at end of file diff --git a/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types b/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types index f450307758ddd..72fd6281ba9cd 100644 --- a/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types +++ b/tests/baselines/reference/logicalOrExpressionIsNotContextuallyTyped.types @@ -11,14 +11,14 @@ var a: (a: string) => string; // bug 786110 var r = a || ((a) => a.toLowerCase()); ->r : (a: any) => any ->a || ((a) => a.toLowerCase()) : (a: any) => any +>r : (a: string) => string +>a || ((a) => a.toLowerCase()) : (a: string) => string >a : (a: string) => string ->((a) => a.toLowerCase()) : (a: any) => any ->(a) => a.toLowerCase() : (a: any) => any ->a : any ->a.toLowerCase() : any ->a.toLowerCase : any ->a : any ->toLowerCase : any +>((a) => a.toLowerCase()) : (a: string) => string +>(a) => a.toLowerCase() : (a: string) => string +>a : string +>a.toLowerCase() : string +>a.toLowerCase : () => string +>a : string +>toLowerCase : () => string diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.types b/tests/baselines/reference/parenthesizedContexualTyping1.types index c8685206c474f..60020fd8eb290 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping1.types +++ b/tests/baselines/reference/parenthesizedContexualTyping1.types @@ -52,34 +52,34 @@ var a = fun(x => x, 10); >x : number var b = fun((x => x), 10); ->b : any ->fun((x => x), 10) : any +>b : number +>fun((x => x), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var c = fun(((x => x)), 10); ->c : any ->fun(((x => x)), 10) : any +>c : number +>fun(((x => x)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var d = fun((((x => x))), 10); ->d : any ->fun((((x => x))), 10) : any +>d : number +>fun((((x => x))), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(((x => x))) : (x: any) => any ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(((x => x))) : (x: number) => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var e = fun(x => x, x => x, 10); >e : number @@ -93,106 +93,106 @@ var e = fun(x => x, x => x, 10); >x : number var f = fun((x => x), (x => x), 10); ->f : any ->fun((x => x), (x => x), 10) : any +>f : number +>fun((x => x), (x => x), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var g = fun(((x => x)), ((x => x)), 10); ->g : any ->fun(((x => x)), ((x => x)), 10) : any +>g : number +>fun(((x => x)), ((x => x)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var h = fun((((x => x))), ((x => x)), 10); ->h : any ->fun((((x => x))), ((x => x)), 10) : any +>h : number +>fun((((x => x))), ((x => x)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(((x => x))) : (x: any) => any ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(((x => x))) : (x: number) => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number // Ternaries in parens var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); >i : any >fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : any >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(Math.random() < 0.5 ? x => x : x => undefined) : (x: any) => any ->Math.random() < 0.5 ? x => x : x => undefined : (x: any) => any +>(Math.random() < 0.5 ? x => x : x => undefined) : (x: number) => any +>Math.random() < 0.5 ? x => x : x => undefined : (x: number) => any >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number >Math : Math >random : () => number ->x => x : (x: any) => any ->x : any ->x : any ->x => undefined : (x: any) => any ->x : any +>x => x : (x: number) => number +>x : number +>x : number +>x => undefined : (x: number) => any +>x : number >undefined : undefined var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); >j : any >fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : any >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: any) => any ->Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: any) => any +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any +>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number >Math : Math >random : () => number ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->(x => undefined) : (x: any) => any ->x => undefined : (x: any) => any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(x => undefined) : (x: number) => any +>x => undefined : (x: number) => any +>x : number >undefined : undefined var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); >k : any >fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: any) => any ->Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: any) => any +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any +>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number >Math : Math >random : () => number ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->(x => undefined) : (x: any) => any ->x => undefined : (x: any) => any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(x => undefined) : (x: number) => any +>x => undefined : (x: number) => any +>x : number >undefined : undefined >x => x : (x: any) => any >x : any @@ -202,29 +202,29 @@ var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x) >l : any >fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: any) => any ->(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: any) => any ->Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : (x: any) => any +>((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: number) => any +>(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: number) => any +>Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : (x: number) => any >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number >Math : Math >random : () => number ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->((x => undefined)) : (x: any) => any ->(x => undefined) : (x: any) => any ->x => undefined : (x: any) => any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>((x => undefined)) : (x: number) => any +>(x => undefined) : (x: number) => any +>x => undefined : (x: number) => any +>x : number >undefined : undefined ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var lambda1: (x: number) => number = x => x; >lambda1 : (x: number) => number @@ -236,10 +236,10 @@ var lambda1: (x: number) => number = x => x; var lambda2: (x: number) => number = (x => x); >lambda2 : (x: number) => number >x : number ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number type ObjType = { x: (p: number) => string; y: (p: string) => number }; >ObjType : { x: (p: number) => string; y: (p: string) => number; } @@ -270,20 +270,20 @@ var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); >obj2 : { x: (p: number) => string; y: (p: string) => number; } >ObjType : { x: (p: number) => string; y: (p: string) => number; } ->({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: any) => any; y: (y: any) => any; } ->{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: any) => any; y: (y: any) => any; } ->x : (x: any) => any ->x => (x, undefined) : (x: any) => any ->x : any +>({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: number) => any; y: (y: string) => any; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number >(x, undefined) : undefined >x, undefined : undefined ->x : any +>x : number >undefined : undefined ->y : (y: any) => any ->y => (y, undefined) : (y: any) => any ->y : any +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string >(y, undefined) : undefined >y, undefined : undefined ->y : any +>y : string >undefined : undefined diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt b/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt deleted file mode 100644 index e4a9f0df708b1..0000000000000 --- a/tests/baselines/reference/parenthesizedContexualTyping2.errors.txt +++ /dev/null @@ -1,84 +0,0 @@ -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(16,21): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(17,22): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(18,23): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,21): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,64): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,22): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,67): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(23,23): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(23,69): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(26,43): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(27,44): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,44): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(29,46): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(29,114): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(32,33): error TS2347: Untyped function calls may not accept type arguments. - - -==== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts (15 errors) ==== - // These tests ensure that in cases where it may *appear* that a value has a type, - // they actually are properly being contextually typed. The way we test this is - // that we invoke contextually typed arguments with type arguments. - // Since 'any' cannot be invoked with type arguments, we should get errors - // back if contextual typing is not taking effect. - - type FuncType = (x: (p: T) => T) => typeof x; - - function fun(f: FuncType, x: T): T; - function fun(f: FuncType, g: FuncType, x: T): T; - function fun(...rest: any[]): T { - return undefined; - } - - var a = fun(x => { x(undefined); return x; }, 10); - var b = fun((x => { x(undefined); return x; }), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var c = fun(((x => { x(undefined); return x; })), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var d = fun((((x => { x(undefined); return x; }))), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - - var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); - var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - - // Ternaries in parens - var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - - var lambda1: FuncType = x => { x(undefined); return x; }; - var lambda2: FuncType = (x => { x(undefined); return x; }); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2347: Untyped function calls may not accept type arguments. - - type ObjType = { x: (p: number) => string; y: (p: string) => number }; - var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; - var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); \ No newline at end of file diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.types b/tests/baselines/reference/parenthesizedContexualTyping2.types new file mode 100644 index 0000000000000..6824cc0f6e97f --- /dev/null +++ b/tests/baselines/reference/parenthesizedContexualTyping2.types @@ -0,0 +1,350 @@ +=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts === +// These tests ensure that in cases where it may *appear* that a value has a type, +// they actually are properly being contextually typed. The way we test this is +// that we invoke contextually typed arguments with type arguments. +// Since 'any' cannot be invoked with type arguments, we should get errors +// back if contextual typing is not taking effect. + +type FuncType = (x: (p: T) => T) => typeof x; +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>T : T +>p : T +>T : T +>T : T +>x : (p: T) => T + +function fun(f: FuncType, x: T): T; +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>f : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : T +>T : T +>T : T + +function fun(f: FuncType, g: FuncType, x: T): T; +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>f : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>g : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x : T +>T : T +>T : T + +function fun(...rest: any[]): T { +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>T : T +>rest : any[] +>T : T + + return undefined; +>undefined : undefined +} + +var a = fun(x => { x(undefined); return x; }, 10); +>a : number +>fun(x => { x(undefined); return x; }, 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var b = fun((x => { x(undefined); return x; }), 10); +>b : number +>fun((x => { x(undefined); return x; }), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var c = fun(((x => { x(undefined); return x; })), 10); +>c : number +>fun(((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var d = fun((((x => { x(undefined); return x; }))), 10); +>d : number +>fun((((x => { x(undefined); return x; }))), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(((x => { x(undefined); return x; }))) : (x: (p: T) => T) => (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); +>e : number +>fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); +>f : number +>fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); +>g : number +>fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); +>h : number +>fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(((x => { x(undefined); return x; }))) : (x: (p: T) => T) => (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +// Ternaries in parens +var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); +>i : number +>fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined + +var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); +>j : number +>fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(x => undefined) : (x: (p: T) => T) => any +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined + +var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); +>k : number +>fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>(x => undefined) : (x: (p: T) => T) => any +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); +>l : number +>fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10) : number +>fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))) : (x: (p: T) => T) => any +>(Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined))) : (x: (p: T) => T) => any +>Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)) : (x: (p: T) => T) => any +>Math.random() < 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T +>((x => undefined)) : (x: (p: T) => T) => any +>(x => undefined) : (x: (p: T) => T) => any +>x => undefined : (x: (p: T) => T) => any +>x : (p: T) => T +>undefined : undefined +>((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var lambda1: FuncType = x => { x(undefined); return x; }; +>lambda1 : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +var lambda2: FuncType = (x => { x(undefined); return x; }); +>lambda2 : (x: (p: T) => T) => (p: T) => T +>FuncType : (x: (p: T) => T) => (p: T) => T +>(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T +>x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T +>x : (p: T) => T +>x(undefined) : number +>x : (p: T) => T +>undefined : undefined +>x : (p: T) => T + +type ObjType = { x: (p: number) => string; y: (p: string) => number }; +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>x : (p: number) => string +>p : number +>y : (p: string) => number +>p : string + +var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) }; +>obj1 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + +var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) }); +>obj2 : { x: (p: number) => string; y: (p: string) => number; } +>ObjType : { x: (p: number) => string; y: (p: string) => number; } +>({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: number) => any; y: (y: string) => any; } +>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; } +>x : (x: number) => any +>x => (x, undefined) : (x: number) => any +>x : number +>(x, undefined) : undefined +>x, undefined : undefined +>x : number +>undefined : undefined +>y : (y: string) => any +>y => (y, undefined) : (y: string) => any +>y : string +>(y, undefined) : undefined +>y, undefined : undefined +>y : string +>undefined : undefined + diff --git a/tests/baselines/reference/parenthesizedContexualTyping3.types b/tests/baselines/reference/parenthesizedContexualTyping3.types index 6f9f24ef90b12..26c0207e52371 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping3.types +++ b/tests/baselines/reference/parenthesizedContexualTyping3.types @@ -62,21 +62,21 @@ var a = tempFun `${ x => x } ${ 10 }` >x : number var b = tempFun `${ (x => x) } ${ 10 }` ->b : any +>b : number >tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var c = tempFun `${ ((x => x)) } ${ 10 }` ->c : any +>c : number >tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var d = tempFun `${ x => x } ${ x => x } ${ 10 }` >d : number @@ -89,41 +89,41 @@ var d = tempFun `${ x => x } ${ x => x } ${ 10 }` >x : number var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }` ->e : any +>e : number >tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } ->x => x : (x: any) => any ->x : any ->x : any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>x => x : (x: number) => number +>x : number +>x : number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }` ->f : any +>f : number >tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } ->x => x : (x: any) => any ->x : any ->x : any ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>x => x : (x: number) => number +>x : number +>x : number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }` ->g : any +>g : number >tempFun : { (tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; (tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any ->(((x => x))) : (x: any) => any ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number +>(((x => x))) : (x: number) => number +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }` >h : any diff --git a/tests/cases/fourslash/assertContextualType.ts b/tests/cases/fourslash/assertContextualType.ts index 36a5958382527..7e057ce61d8e6 100644 --- a/tests/cases/fourslash/assertContextualType.ts +++ b/tests/cases/fourslash/assertContextualType.ts @@ -6,4 +6,4 @@ edit.insert(''); goTo.marker(); -verify.quickInfoIs('(parameter) bb: any'); \ No newline at end of file +verify.quickInfoIs('(parameter) bb: number'); \ No newline at end of file diff --git a/tests/cases/fourslash/contextualTyping.ts b/tests/cases/fourslash/contextualTyping.ts index 13fb4dc2450fa..c363302f7a181 100644 --- a/tests/cases/fourslash/contextualTyping.ts +++ b/tests/cases/fourslash/contextualTyping.ts @@ -212,9 +212,9 @@ verify.quickInfoIs("(parameter) i: number"); goTo.marker('7'); verify.quickInfoIs("(var) c3t1: (s: string) => string"); goTo.marker('8'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('9'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('10'); verify.quickInfoIs("(var) c3t2: IFoo"); goTo.marker('11'); @@ -254,11 +254,11 @@ verify.quickInfoIs("(property) foo: IFoo"); goTo.marker('29'); verify.quickInfoIs("(var) c3t13: IFoo"); goTo.marker('30'); -verify.quickInfoIs("(property) f: (i: any, s: any) => any"); +verify.quickInfoIs("(property) f: (i: number, s: string) => string"); goTo.marker('31'); -verify.quickInfoIs("(parameter) i: any"); +verify.quickInfoIs("(parameter) i: number"); goTo.marker('32'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('33'); verify.quickInfoIs("(var) c3t14: IFoo"); goTo.marker('34'); @@ -286,7 +286,7 @@ verify.quickInfoIs("(var) c7t2: IFoo[]"); goTo.marker('45'); verify.quickInfoIs("(property) t1: (s: string) => string"); goTo.marker('46'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('47'); verify.quickInfoIs("(property) t2: IFoo"); goTo.marker('48'); @@ -326,11 +326,11 @@ verify.quickInfoIs("(property) foo: IFoo"); goTo.marker('65'); verify.quickInfoIs("(property) t13: IFoo"); goTo.marker('66'); -verify.quickInfoIs("(property) f: (i: any, s: any) => any"); +verify.quickInfoIs("(property) f: (i: number, s: string) => string"); goTo.marker('67'); -verify.quickInfoIs("(parameter) i: any"); +verify.quickInfoIs("(parameter) i: number"); goTo.marker('68'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('69'); verify.quickInfoIs("(property) t14: IFoo"); goTo.marker('70'); @@ -346,7 +346,7 @@ verify.quickInfoIs("(parameter) n: number"); goTo.marker('75'); verify.quickInfoIs("(var) c12t1: (s: string) => string"); goTo.marker('76'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('77'); verify.quickInfoIs("(var) c12t2: IFoo"); goTo.marker('78'); @@ -386,11 +386,11 @@ verify.quickInfoIs("(property) foo: IFoo"); goTo.marker('95'); verify.quickInfoIs("(var) c12t13: IFoo"); goTo.marker('96'); -verify.quickInfoIs("(property) f: (i: any, s: any) => any"); +verify.quickInfoIs("(property) f: (i: number, s: string) => string"); goTo.marker('97'); -verify.quickInfoIs("(parameter) i: any"); +verify.quickInfoIs("(parameter) i: number"); goTo.marker('98'); -verify.quickInfoIs("(parameter) s: any"); +verify.quickInfoIs("(parameter) s: string"); goTo.marker('99'); verify.quickInfoIs("(var) c12t14: IFoo"); goTo.marker('100'); From 6783e35f89c54cbf8797511693d9775716742de6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sun, 11 Jan 2015 00:21:37 -0800 Subject: [PATCH 5/5] Removed probably-unnecessary statement from test. --- tests/cases/fourslash/assertContextualType.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/cases/fourslash/assertContextualType.ts b/tests/cases/fourslash/assertContextualType.ts index 7e057ce61d8e6..6ee8861ee8cb7 100644 --- a/tests/cases/fourslash/assertContextualType.ts +++ b/tests/cases/fourslash/assertContextualType.ts @@ -2,8 +2,5 @@ ////<(aa: number) =>void >(function myFn(b/**/b) { }); -// this line triggers a semantic/syntactic error check, remove line when 788570 is fixed -edit.insert(''); - goTo.marker(); verify.quickInfoIs('(parameter) bb: number'); \ No newline at end of file