diff --git a/tests/baselines/reference/defaultArgsForwardReferencing.errors.txt b/tests/baselines/reference/defaultArgsForwardReferencing.errors.txt deleted file mode 100644 index d44594eb114b5..0000000000000 --- a/tests/baselines/reference/defaultArgsForwardReferencing.errors.txt +++ /dev/null @@ -1,70 +0,0 @@ -tests/cases/compiler/defaultArgsForwardReferencing.ts(6,20): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(11,21): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(11,28): error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(17,21): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(23,25): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(32,21): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(33,16): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(37,14): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(37,21): error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. -tests/cases/compiler/defaultArgsForwardReferencing.ts(37,28): error TS2373: Initializer of parameter 'c' cannot reference identifier 'd' declared after it. - - -==== tests/cases/compiler/defaultArgsForwardReferencing.ts (10 errors) ==== - function left(a, b = a, c = b) { - a; - b; - } - - function right(a = b, b = a) { - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - a; - b; - } - - function right2(a = b, b = c, c = a) { - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - ~ -!!! error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. - a; - b; - c; - } - - function inside(a = b) { - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - var b; - } - - function outside() { - var b; - function inside(a = b) { // Still an error because b is declared inside the function - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - var b; - } - } - - function defaultArgFunction(a = function () { return b; }, b = 1) { } - function defaultArgArrow(a = () => () => b, b = 3) { } - - class C { - constructor(a = b, b = 1) { } - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - method(a = b, b = 1) { } - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - } - - // Function expressions - var x = (a = b, b = c, c = d) => { var d; }; - ~ -!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. - ~ -!!! error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. - ~ -!!! error TS2373: Initializer of parameter 'c' cannot reference identifier 'd' declared after it. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt b/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt new file mode 100644 index 0000000000000..8900e9750309a --- /dev/null +++ b/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.errors.txt @@ -0,0 +1,102 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(24,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(53,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(69,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts(85,38): error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; (b: boolean): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts (4 errors) ==== + + module m1 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); + } + + ////////////////////////////////////// + + module m2 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + } + + ////////////////////////////////////// + + module m3 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); + } + + ////////////////////////////////////// + + module m4 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + } + + ////////////////////////////////////// + + module m5 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => U, progress?: (preservation: any) => void): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + } + + ////////////////////////////////////// + + module m6 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + declare function testFunction(b: boolean): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (n: number): Promise; (s: string): Promise; (b: boolean): Promise; }' is not assignable to parameter of type '(x: number) => Promise'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.js b/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.js new file mode 100644 index 0000000000000..9bfb6eec1135b --- /dev/null +++ b/tests/baselines/reference/genericCallToOverloadedMethodWithOverloadedArguments.js @@ -0,0 +1,125 @@ +//// [genericCallToOverloadedMethodWithOverloadedArguments.ts] + +module m1 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m2 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m3 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m4 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m5 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => U, progress?: (preservation: any) => void): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m6 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + declare function testFunction(b: boolean): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + + +//// [genericCallToOverloadedMethodWithOverloadedArguments.js] +var m1; +(function (m1) { + var numPromise; + var newPromise = numPromise.then(testFunction); +})(m1 || (m1 = {})); +////////////////////////////////////// +var m2; +(function (m2) { + var numPromise; + var newPromise = numPromise.then(testFunction); +})(m2 || (m2 = {})); +////////////////////////////////////// +var m3; +(function (m3) { + var numPromise; + var newPromise = numPromise.then(testFunction); +})(m3 || (m3 = {})); +////////////////////////////////////// +var m4; +(function (m4) { + var numPromise; + var newPromise = numPromise.then(testFunction); +})(m4 || (m4 = {})); +////////////////////////////////////// +var m5; +(function (m5) { + var numPromise; + var newPromise = numPromise.then(testFunction); +})(m5 || (m5 = {})); +////////////////////////////////////// +var m6; +(function (m6) { + var numPromise; + var newPromise = numPromise.then(testFunction); +})(m6 || (m6 = {})); diff --git a/tests/baselines/reference/moduleWithStatementsOfEveryKind.js b/tests/baselines/reference/moduleWithStatementsOfEveryKind.js index d30c36584b865..8496588c5bb4c 100644 --- a/tests/baselines/reference/moduleWithStatementsOfEveryKind.js +++ b/tests/baselines/reference/moduleWithStatementsOfEveryKind.js @@ -22,6 +22,10 @@ module A { return 'hello ' + s; } var ol = { s: 'hello', id: 2, isvalid: true }; + + declare class DC { + static x: number; + } } module Y { @@ -47,6 +51,10 @@ module Y { return 'hello ' + s; } export var ol = { s: 'hello', id: 2, isvalid: true }; + + export declare class DC { + static x: number; + } } diff --git a/tests/baselines/reference/moduleWithStatementsOfEveryKind.types b/tests/baselines/reference/moduleWithStatementsOfEveryKind.types index 263da21f52414..0bade1f2d8efe 100644 --- a/tests/baselines/reference/moduleWithStatementsOfEveryKind.types +++ b/tests/baselines/reference/moduleWithStatementsOfEveryKind.types @@ -71,6 +71,13 @@ module A { >s : string >id : number >isvalid : boolean + + declare class DC { +>DC : DC + + static x: number; +>x : number + } } module Y { @@ -145,5 +152,12 @@ module Y { >s : string >id : number >isvalid : boolean + + export declare class DC { +>DC : DC + + static x: number; +>x : number + } } diff --git a/tests/baselines/reference/parameterInitializersForwardReferencing.errors.txt b/tests/baselines/reference/parameterInitializersForwardReferencing.errors.txt new file mode 100644 index 0000000000000..22fe5ce558dba --- /dev/null +++ b/tests/baselines/reference/parameterInitializersForwardReferencing.errors.txt @@ -0,0 +1,74 @@ +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(6,20): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(11,21): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(11,28): error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(17,21): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(23,25): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(32,21): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(33,16): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(37,14): error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(37,21): error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. +tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts(37,28): error TS2373: Initializer of parameter 'c' cannot reference identifier 'd' declared after it. + + +==== tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts (10 errors) ==== + function left(a, b = a, c = b) { + a; + b; + } + + function right(a = b, b = a) { + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + a; + b; + } + + function right2(a = b, b = c, c = a) { + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + ~ +!!! error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. + a; + b; + c; + } + + function inside(a = b) { + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + var b; + } + + function outside() { + var b; + function inside(a = b) { // Still an error because b is declared inside the function + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + var b; + } + } + + function defaultArgFunction(a = function () { return b; }, b = 1) { } + function defaultArgArrow(a = () => () => b, b = 3) { } + + class C { + constructor(a = b, b = 1) { } + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + method(a = b, b = 1) { } + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + } + + // Function expressions + var x = (a = b, b = c, c = d) => { var d; }; + ~ +!!! error TS2373: Initializer of parameter 'a' cannot reference identifier 'b' declared after it. + ~ +!!! error TS2373: Initializer of parameter 'b' cannot reference identifier 'c' declared after it. + ~ +!!! error TS2373: Initializer of parameter 'c' cannot reference identifier 'd' declared after it. + + // Should not produce errors - can reference later parameters if they occur within a function expression initializer. + function f(a, b = function () { return c; }, c = b()) { + } \ No newline at end of file diff --git a/tests/baselines/reference/defaultArgsForwardReferencing.js b/tests/baselines/reference/parameterInitializersForwardReferencing.js similarity index 76% rename from tests/baselines/reference/defaultArgsForwardReferencing.js rename to tests/baselines/reference/parameterInitializersForwardReferencing.js index 4e9a5ae60e343..90fa1bdcd23e3 100644 --- a/tests/baselines/reference/defaultArgsForwardReferencing.js +++ b/tests/baselines/reference/parameterInitializersForwardReferencing.js @@ -1,4 +1,4 @@ -//// [defaultArgsForwardReferencing.ts] +//// [parameterInitializersForwardReferencing.ts] function left(a, b = a, c = b) { a; b; @@ -35,9 +35,13 @@ class C { } // Function expressions -var x = (a = b, b = c, c = d) => { var d; }; +var x = (a = b, b = c, c = d) => { var d; }; + +// Should not produce errors - can reference later parameters if they occur within a function expression initializer. +function f(a, b = function () { return c; }, c = b()) { +} -//// [defaultArgsForwardReferencing.js] +//// [parameterInitializersForwardReferencing.js] function left(a, b, c) { if (b === void 0) { b = a; } if (c === void 0) { c = b; } @@ -97,3 +101,10 @@ var x = function (a, b, c) { if (c === void 0) { c = d; } var d; }; +// Should not produce errors - can reference later parameters if they occur within a function expression initializer. +function f(a, b, c) { + if (b === void 0) { b = function () { + return c; + }; } + if (c === void 0) { c = b(); } +} diff --git a/tests/cases/compiler/defaultArgsForwardReferencing.ts b/tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts similarity index 68% rename from tests/cases/compiler/defaultArgsForwardReferencing.ts rename to tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts index c169f7d23e898..fa3549ea2c5bd 100644 --- a/tests/cases/compiler/defaultArgsForwardReferencing.ts +++ b/tests/cases/conformance/functions/parameterInitializersForwardReferencing.ts @@ -34,4 +34,8 @@ class C { } // Function expressions -var x = (a = b, b = c, c = d) => { var d; }; \ No newline at end of file +var x = (a = b, b = c, c = d) => { var d; }; + +// Should not produce errors - can reference later parameters if they occur within a function expression initializer. +function f(a, b = function () { return c; }, c = b()) { +} \ No newline at end of file diff --git a/tests/cases/conformance/internalModules/moduleBody/moduleWithStatementsOfEveryKind.ts b/tests/cases/conformance/internalModules/moduleBody/moduleWithStatementsOfEveryKind.ts index 202c84013ed31..6991795b26c8f 100644 --- a/tests/cases/conformance/internalModules/moduleBody/moduleWithStatementsOfEveryKind.ts +++ b/tests/cases/conformance/internalModules/moduleBody/moduleWithStatementsOfEveryKind.ts @@ -21,6 +21,10 @@ module A { return 'hello ' + s; } var ol = { s: 'hello', id: 2, isvalid: true }; + + declare class DC { + static x: number; + } } module Y { @@ -46,4 +50,8 @@ module Y { return 'hello ' + s; } export var ol = { s: 'hello', id: 2, isvalid: true }; + + export declare class DC { + static x: number; + } } diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts new file mode 100644 index 0000000000000..b1db7364ab28a --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallToOverloadedMethodWithOverloadedArguments.ts @@ -0,0 +1,86 @@ + +module m1 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m2 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m3 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m4 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m5 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => U, progress?: (preservation: any) => void): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +} + +////////////////////////////////////// + +module m6 { + interface Promise { + then(cb: (x: T) => Promise): Promise; + then(cb: (x: T) => Promise, error?: (error: any) => Promise): Promise; + } + + declare function testFunction(n: number): Promise; + declare function testFunction(s: string): Promise; + declare function testFunction(b: boolean): Promise; + + var numPromise: Promise; + var newPromise = numPromise.then(testFunction); +}