diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d393f9783c..b133245d837 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5234,7 +5234,7 @@ module ts { } var index = excludeArgument ? indexOf(excludeArgument, true) : -1; if (index < 0) { - return candidates[i] = candidate; + return candidate; } excludeArgument[index] = false; } @@ -5246,7 +5246,6 @@ module ts { // arguments, then we can only report an error based on the type arguments. if (originalCandidate.typeParameters) { var instantiatedCandidate = candidate; - candidates[i] = instantiatedCandidate; if (typeArgumentsAreValid) { candidateForArgumentError = instantiatedCandidate; } diff --git a/tests/baselines/reference/overloadResolution.errors.txt b/tests/baselines/reference/overloadResolution.errors.txt index 1d9f6cb6296..e0a65f7475e 100644 --- a/tests/baselines/reference/overloadResolution.errors.txt +++ b/tests/baselines/reference/overloadResolution.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(27,5): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(41,11): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(63,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(70,5): error TS2344: Type 'string' does not satisfy the constraint 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(71,5): error TS2344: Type 'number' does not satisfy the constraint 'string'. +tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(70,21): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. +tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(71,21): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(81,5): error TS2344: Type 'boolean' does not satisfy the constraint 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(84,5): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(85,11): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. @@ -87,11 +87,11 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(91,22): function fn4() { } fn4('', 3); fn4(3, ''); // Error - ~~~~~~ -!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. fn4('', 3); // Error - ~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint 'string'. + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. fn4(3, ''); // Generic overloads with constraints called without type arguments but with types that satisfy the constraints diff --git a/tests/baselines/reference/overloadResolutionConstructors.errors.txt b/tests/baselines/reference/overloadResolutionConstructors.errors.txt index 19052cc3f50..540e12774c7 100644 --- a/tests/baselines/reference/overloadResolutionConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionConstructors.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(27,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(43,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(43,15): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(67,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(77,9): error TS2344: Type 'string' does not satisfy the constraint 'number'. -tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(78,9): error TS2344: Type 'number' does not satisfy the constraint 'string'. +tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(77,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. +tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(78,25): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(88,9): error TS2344: Type 'boolean' does not satisfy the constraint 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(91,9): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'. tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(92,15): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. @@ -56,8 +56,8 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors // Generic and non - generic overload where non - generic overload is the only candidate when called with type arguments new fn2('', 0); // Error - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. // Generic and non - generic overload where non - generic overload is the only candidate when called without type arguments new fn2('', 0); // OK @@ -94,11 +94,11 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors new fn4('', 3); new fn4(3, ''); // Error - ~~~~~~ -!!! error TS2344: Type 'string' does not satisfy the constraint 'number'. + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. new fn4('', 3); // Error - ~~~~~~ -!!! error TS2344: Type 'number' does not satisfy the constraint 'string'. + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. new fn4(3, ''); // Generic overloads with constraints called without type arguments but with types that satisfy the constraints diff --git a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt index e41557a2903..80472228380 100644 --- a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt +++ b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,5): error TS2323: Type 'string' is not assignable to type 'number'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,37): error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'. -tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,27): error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. +tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,5): error TS2323: Type 'string' is not assignable to type 'number'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,38): error TS2344: Type 'D' does not satisfy the constraint 'A'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(18,27): error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12): error TS2344: Type 'D' does not satisfy the constraint 'A'. @@ -20,22 +20,22 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,12): declare function foo(arg: (x: C) => any): string; declare function foo(arg: (x: B) => any): number; - var result: number = foo(x => new G(x)); // No error, returns number + var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. ~~~~~~ !!! error TS2323: Type 'string' is not assignable to type 'number'. ~ !!! error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'. - var result2: number = foo(x => new G(x)); // No error, returns number - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. + var result2: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. + ~~~~~~~ +!!! error TS2323: Type 'string' is not assignable to type 'number'. ~~~~~~~~ !!! error TS2344: Type 'D' does not satisfy the constraint 'A'. - var result3: string = foo(x => { // returns string because the C overload is picked - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - var y: G; // error that C does not satisfy constraint - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + var result3: string = foo(x => { // x has type D + ~~~~~~~~~~~~~~~~~~~~~~ + var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ !!! error TS2344: Type 'D' does not satisfy the constraint 'A'. return y; diff --git a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.js b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.js index 0e5f84c8d69..63b4a2b1e93 100644 --- a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.js +++ b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.js @@ -12,12 +12,12 @@ declare function foo(arg: (x: D) => number): string; declare function foo(arg: (x: C) => any): string; declare function foo(arg: (x: B) => any): number; -var result: number = foo(x => new G(x)); // No error, returns number +var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. -var result2: number = foo(x => new G(x)); // No error, returns number +var result2: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. -var result3: string = foo(x => { // returns string because the C overload is picked - var y: G; // error that C does not satisfy constraint +var result3: string = foo(x => { // x has type D + var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y; }); @@ -28,9 +28,9 @@ var G = (function () { } return G; })(); -var result = foo(function (x) { return new G(x); }); // No error, returns number -var result2 = foo(function (x) { return new G(x); }); // No error, returns number +var result = foo(function (x) { return new G(x); }); // x has type D, new G(x) fails, so first overload is picked. +var result2 = foo(function (x) { return new G(x); }); // x has type D, new G(x) fails, so first overload is picked. var result3 = foo(function (x) { - var y; // error that C does not satisfy constraint + var y; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y; }); diff --git a/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt b/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt index b650b09c143..1131b6e1a68 100644 --- a/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt +++ b/tests/baselines/reference/typeArgumentConstraintResolution1.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/typeArgumentConstraintResolution1.ts(4,6): error TS2344: Type 'Date' does not satisfy the constraint 'Number'. -tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,6): error TS2344: Type 'Date' does not satisfy the constraint 'Number'. +tests/cases/compiler/typeArgumentConstraintResolution1.ts(4,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. +tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. ==== tests/cases/compiler/typeArgumentConstraintResolution1.ts (2 errors) ==== @@ -7,8 +7,8 @@ tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,6): error TS2344: T function foo1(test: string); function foo1(test: any) { } foo1(""); // should error - ~~~~ -!!! error TS2344: Type 'Date' does not satisfy the constraint 'Number'. + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. @@ -16,6 +16,6 @@ tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,6): error TS2344: T function foo2(test: string): T; function foo2(test: any): any { return null; } foo2(""); // Type Date does not satisfy the constraint 'Number' for type parameter 'T extends Number' - ~~~~ -!!! error TS2344: Type 'Date' does not satisfy the constraint 'Number'. + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'. \ No newline at end of file diff --git a/tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts b/tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts index bf6007560e8..a139eb85572 100644 --- a/tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts +++ b/tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts @@ -11,11 +11,11 @@ declare function foo(arg: (x: D) => number): string; declare function foo(arg: (x: C) => any): string; declare function foo(arg: (x: B) => any): number; -var result: number = foo(x => new G(x)); // No error, returns number +var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. -var result2: number = foo(x => new G(x)); // No error, returns number +var result2: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. -var result3: string = foo(x => { // returns string because the C overload is picked - var y: G; // error that C does not satisfy constraint +var result3: string = foo(x => { // x has type D + var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y; });