Skip to content

Commit e8d5fdc

Browse files
committed
Revert the stuffing of instantiated signatures back into the candidates array
1 parent 44f1ab0 commit e8d5fdc

7 files changed

Lines changed: 42 additions & 43 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5234,7 +5234,7 @@ module ts {
52345234
}
52355235
var index = excludeArgument ? indexOf(excludeArgument, true) : -1;
52365236
if (index < 0) {
5237-
return candidates[i] = candidate;
5237+
return candidate;
52385238
}
52395239
excludeArgument[index] = false;
52405240
}
@@ -5246,7 +5246,6 @@ module ts {
52465246
// arguments, then we can only report an error based on the type arguments.
52475247
if (originalCandidate.typeParameters) {
52485248
var instantiatedCandidate = candidate;
5249-
candidates[i] = instantiatedCandidate;
52505249
if (typeArgumentsAreValid) {
52515250
candidateForArgumentError = instantiatedCandidate;
52525251
}

tests/baselines/reference/overloadResolution.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(27,5): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'.
22
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(41,11): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
33
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(63,1): error TS2346: Supplied parameters do not match any signature of call target.
4-
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(70,5): error TS2344: Type 'string' does not satisfy the constraint 'number'.
5-
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(71,5): error TS2344: Type 'number' does not satisfy the constraint 'string'.
4+
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(70,21): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
5+
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(71,21): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
66
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(81,5): error TS2344: Type 'boolean' does not satisfy the constraint 'number'.
77
tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(84,5): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'.
88
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):
8787
function fn4() { }
8888
fn4<string, number>('', 3);
8989
fn4<string, number>(3, ''); // Error
90-
~~~~~~
91-
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
90+
~
91+
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
9292
fn4<number, string>('', 3); // Error
93-
~~~~~~
94-
!!! error TS2344: Type 'number' does not satisfy the constraint 'string'.
93+
~~
94+
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
9595
fn4<number, string>(3, '');
9696

9797
// Generic overloads with constraints called without type arguments but with types that satisfy the constraints

tests/baselines/reference/overloadResolutionConstructors.errors.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(27,9): error TS2345: Argument of type '{}' is not assignable to parameter of type 'number'.
2-
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(43,1): error TS2346: Supplied parameters do not match any signature of call target.
2+
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(43,15): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
33
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(67,1): error TS2346: Supplied parameters do not match any signature of call target.
4-
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(77,9): error TS2344: Type 'string' does not satisfy the constraint 'number'.
5-
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(78,9): error TS2344: Type 'number' does not satisfy the constraint 'string'.
4+
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(77,25): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
5+
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(78,25): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
66
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(88,9): error TS2344: Type 'boolean' does not satisfy the constraint 'number'.
77
tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts(91,9): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'.
88
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
5656

5757
// Generic and non - generic overload where non - generic overload is the only candidate when called with type arguments
5858
new fn2<Date>('', 0); // Error
59-
~~~~~~~~~~~~~~~~~~~~
60-
!!! error TS2346: Supplied parameters do not match any signature of call target.
59+
~~
60+
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
6161

6262
// Generic and non - generic overload where non - generic overload is the only candidate when called without type arguments
6363
new fn2('', 0); // OK
@@ -94,11 +94,11 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors
9494

9595
new fn4<string, number>('', 3);
9696
new fn4<string, number>(3, ''); // Error
97-
~~~~~~
98-
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
97+
~
98+
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
9999
new fn4<number, string>('', 3); // Error
100-
~~~~~~
101-
!!! error TS2344: Type 'number' does not satisfy the constraint 'string'.
100+
~~
101+
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
102102
new fn4<number, string>(3, '');
103103

104104
// Generic overloads with constraints called without type arguments but with types that satisfy the constraints

tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,5): error TS2323: Type 'string' is not assignable to type 'number'.
22
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,37): error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'.
3-
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,27): error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
3+
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,5): error TS2323: Type 'string' is not assignable to type 'number'.
44
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,38): error TS2344: Type 'D' does not satisfy the constraint 'A'.
55
tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(18,27): error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
66
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):
2020
declare function foo(arg: (x: C) => any): string;
2121
declare function foo(arg: (x: B) => any): number;
2222

23-
var result: number = foo(x => new G(x)); // No error, returns number
23+
var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
2424
~~~~~~
2525
!!! error TS2323: Type 'string' is not assignable to type 'number'.
2626
~
2727
!!! error TS2345: Argument of type 'D' is not assignable to parameter of type 'A'.
2828

29-
var result2: number = foo(x => new G<typeof x>(x)); // No error, returns number
30-
~~~~~~~~~~~~~~~~~~~~~~~
31-
!!! error TS2345: Argument of type '(x: D) => G<D>' is not assignable to parameter of type '(x: B) => any'.
29+
var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
30+
~~~~~~~
31+
!!! error TS2323: Type 'string' is not assignable to type 'number'.
3232
~~~~~~~~
3333
!!! error TS2344: Type 'D' does not satisfy the constraint 'A'.
3434

35-
var result3: string = foo(x => { // returns string because the C overload is picked
36-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37-
var y: G<typeof x>; // error that C does not satisfy constraint
38-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
var result3: string = foo(x => { // x has type D
36+
~~~~~~~~~~~~~~~~~~~~~~
37+
var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
38+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939
~~~~~~~~~~~
4040
!!! error TS2344: Type 'D' does not satisfy the constraint 'A'.
4141
return y;

tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ declare function foo(arg: (x: D) => number): string;
1212
declare function foo(arg: (x: C) => any): string;
1313
declare function foo(arg: (x: B) => any): number;
1414

15-
var result: number = foo(x => new G(x)); // No error, returns number
15+
var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
1616

17-
var result2: number = foo(x => new G<typeof x>(x)); // No error, returns number
17+
var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
1818

19-
var result3: string = foo(x => { // returns string because the C overload is picked
20-
var y: G<typeof x>; // error that C does not satisfy constraint
19+
var result3: string = foo(x => { // x has type D
20+
var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
2121
return y;
2222
});
2323

@@ -28,9 +28,9 @@ var G = (function () {
2828
}
2929
return G;
3030
})();
31-
var result = foo(function (x) { return new G(x); }); // No error, returns number
32-
var result2 = foo(function (x) { return new G(x); }); // No error, returns number
31+
var result = foo(function (x) { return new G(x); }); // x has type D, new G(x) fails, so first overload is picked.
32+
var result2 = foo(function (x) { return new G(x); }); // x has type D, new G(x) fails, so first overload is picked.
3333
var result3 = foo(function (x) {
34-
var y; // error that C does not satisfy constraint
34+
var y; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
3535
return y;
3636
});
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
tests/cases/compiler/typeArgumentConstraintResolution1.ts(4,6): error TS2344: Type 'Date' does not satisfy the constraint 'Number'.
2-
tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,6): error TS2344: Type 'Date' does not satisfy the constraint 'Number'.
1+
tests/cases/compiler/typeArgumentConstraintResolution1.ts(4,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'.
2+
tests/cases/compiler/typeArgumentConstraintResolution1.ts(11,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'.
33

44

55
==== tests/cases/compiler/typeArgumentConstraintResolution1.ts (2 errors) ====
66
function foo1<T extends Date>(test: T);
77
function foo1<T extends Number>(test: string);
88
function foo1<T extends String>(test: any) { }
99
foo1<Date>(""); // should error
10-
~~~~
11-
!!! error TS2344: Type 'Date' does not satisfy the constraint 'Number'.
10+
~~
11+
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'.
1212

1313

1414

1515
function foo2<T extends Date>(test: T): T;
1616
function foo2<T extends Number>(test: string): T;
1717
function foo2<T extends String>(test: any): any { return null; }
1818
foo2<Date>(""); // Type Date does not satisfy the constraint 'Number' for type parameter 'T extends Number'
19-
~~~~
20-
!!! error TS2344: Type 'Date' does not satisfy the constraint 'Number'.
19+
~~
20+
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Date'.
2121

tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ declare function foo(arg: (x: D) => number): string;
1111
declare function foo(arg: (x: C) => any): string;
1212
declare function foo(arg: (x: B) => any): number;
1313

14-
var result: number = foo(x => new G(x)); // No error, returns number
14+
var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked.
1515

16-
var result2: number = foo(x => new G<typeof x>(x)); // No error, returns number
16+
var result2: number = foo(x => new G<typeof x>(x)); // x has type D, new G(x) fails, so first overload is picked.
1717

18-
var result3: string = foo(x => { // returns string because the C overload is picked
19-
var y: G<typeof x>; // error that C does not satisfy constraint
18+
var result3: string = foo(x => { // x has type D
19+
var y: G<typeof x>; // error that D does not satisfy constraint, y is of type G<D>, entire call to foo is an error
2020
return y;
2121
});

0 commit comments

Comments
 (0)