Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3634,9 +3634,8 @@ module ts {
(!node.typeArguments || signature.typeParameters && node.typeArguments.length === signature.typeParameters.length);
}

// The candidate list is in reverse order of declaration, except that groups of signatures with the same parent are
// kept in declaration order.
function collectCandidates(node: CallExpression, signatures: Signature[]): Signature[] {
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
function collectCandidates(node: CallExpression, signatures: Signature[]): Signature[]{
var result: Signature[] = [];
var lastParent: Node;
var pos: number;
Expand Down Expand Up @@ -3733,15 +3732,22 @@ module ts {
return result;
}

function isApplicableSignature(node: CallExpression, signature: Signature, relation: Map<boolean>, excludeArgument: boolean[]) {
function checkApplicableSignature(node: CallExpression, signature: Signature, relation: Map<boolean>, excludeArgument: boolean[], reportErrors: boolean) {
if (node.arguments) {
for (var i = 0; i < node.arguments.length; i++) {
var arg = node.arguments[i];
var paramType = getTypeAtPosition(signature, i);
var argType = arg.kind === SyntaxKind.StringLiteral ?
// String literals get string literal types unless we're reporting errors
var argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors ?
getStringLiteralType(<LiteralExpression>arg) :
checkExpression(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
if (!isTypeRelatedTo(argType, paramType, relation)) return false;
// Use argument expression as error location when reporting errors
var isValidArgument = checkTypeRelatedTo(argType, paramType, relation, reportErrors ? arg : undefined,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1,
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1);
if (!isValidArgument) {
return false;
}
}
}
return true;
Expand Down Expand Up @@ -3773,18 +3779,24 @@ module ts {
inferTypeArguments(candidate, args, excludeArgument);
candidate = getSignatureInstantiation(candidate, typeArguments);
}
if (!isApplicableSignature(node, candidate, relation, excludeArgument)) break;
if (!checkApplicableSignature(node, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
break;
}
var index = excludeArgument ? indexOf(excludeArgument, true) : -1;
if (index < 0) {
return getReturnTypeOfSignature(candidate);
}
excludeArgument[index] = false;
}
}
if (relation === assignableRelation) break;
if (relation === assignableRelation) {
break;
}
relation = assignableRelation;
}
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
// No signatures were applicable. Now report errors based on the last applicable signature with
// no arguments excluded from assignability checks.
checkApplicableSignature(node, candidate, relation, undefined, /*reportErrors*/ true);
return checkErrorCall(node);
}

Expand Down
1 change: 1 addition & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ module ts {
Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: { code: 3033, category: DiagnosticCategory.Error, key: "Specialized overload signature is not assignable to any non-specialized signature." },
Duplicate_function_implementation: { code: 3034, category: DiagnosticCategory.Error, key: "Duplicate function implementation." },
Overload_signature_is_not_compatible_with_function_implementation: { code: 3035, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." },
Argument_of_type_0_is_not_assignable_to_parameter_of_type_1: { code: 3036, category: DiagnosticCategory.Error, key: "Argument of type '{0}' is not assignable to parameter of type '{1}'." },
Index_signature_is_missing_in_type_0: { code: 4003, category: DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." },
Index_signatures_are_incompatible_Colon: { code: 4004, category: DiagnosticCategory.Error, key: "Index signatures are incompatible:" },
Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function: { code: 4016, category: DiagnosticCategory.NoPrefix, key: "Class '{0}' defines instance member accessor '{1}', but extended class '{2}' defines it as instance member function." },
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,10 @@
"category": "Error",
"code": 3035
},

"Argument of type '{0}' is not assignable to parameter of type '{1}'.": {
"category": "Error",
"code": 3036
},


"Index signature is missing in type '{0}'.": {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayAssignmentTest3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


var xx = new a(null, 7, new B());
~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~
!!! Argument of type 'B' is not assignable to parameter of type 'B[]'.


Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~
!!! Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'.
!!! Type '{}' is not assignable to type 'IAnimal'.
bar(arr); // Error because of no contextual type
~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~
!!! Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
function fn(cb: IResultCallback) { }

fn((a, b) => true);
~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~
!!! Argument of type '(a: any, b: any) => boolean' is not assignable to parameter of type 'IResultCallback'.
!!! Property 'x' is missing in type '(a: any, b: any) => boolean'.
fn(function (a, b) { return true; })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Argument of type '(a: any, b: any) => boolean' is not assignable to parameter of type 'IResultCallback'.
!!! Property 'x' is missing in type '(a: any, b: any) => boolean'.

18 changes: 10 additions & 8 deletions tests/baselines/reference/assignmentCompatBug5.errors.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
==== tests/cases/compiler/assignmentCompatBug5.ts (4 errors) ====
function foo1(x: { a: number; }) { }
foo1({ b: 5 });
~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~
!!! Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
!!! Property 'a' is missing in type '{ b: number; }'.

function foo2(x: number[]) { }
foo2(["s", "t"]);
~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~
!!! Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
!!! Type 'string' is not assignable to type 'number'.

function foo3(x: (n: number) =>number) { };
foo3((s:string) => { });
~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~
!!! Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'.
foo3((n) => { return; });
~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~
!!! Argument of type '(n: number) => void' is not assignable to parameter of type '(n: number) => number'.


Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
foo({ id: 1234 }); // Ok
foo({ id: 1234, name: "hello" }); // Ok
foo({ id: 1234, name: false }); // Error, name of wrong type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Argument of type '{ id: number; name: boolean; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
!!! Types of property 'name' are incompatible:
!!! Type 'boolean' is not assignable to type 'string'.
foo({ name: "hello" }); // Error, id required but missing
~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~
!!! Argument of type '{ name: string; }' is not assignable to parameter of type '{ id: number; name?: string; }'.
!!! Property 'id' is missing in type '{ name: string; }'.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
function Biz(map: IHandlerMap) { }

Biz(new Foo());
~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~
!!! Argument of type 'Foo' is not assignable to parameter of type 'IHandlerMap'.

Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@

// Should Fail
fn('');
~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type 'string' is not assignable to parameter of type 'Applicable'.
fn(['']);
~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~
!!! Argument of type 'string[]' is not assignable to parameter of type 'Applicable'.
fn(4);
~~~~~
!!! Supplied parameters do not match any signature of call target.
~
!!! Argument of type 'number' is not assignable to parameter of type 'Applicable'.
fn({});
~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type '{}' is not assignable to parameter of type 'Applicable'.
!!! Property 'apply' is missing in type '{}'.


// Should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@

// Should Fail
fn('');
~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type 'string' is not assignable to parameter of type 'Callable'.
fn(['']);
~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~
!!! Argument of type 'string[]' is not assignable to parameter of type 'Callable'.
fn(4);
~~~~~
!!! Supplied parameters do not match any signature of call target.
~
!!! Argument of type 'number' is not assignable to parameter of type 'Callable'.
fn({});
~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type '{}' is not assignable to parameter of type 'Callable'.
!!! Property 'call' is missing in type '{}'.


// Should work
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/baseCheck.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
~~~~
!!! 'this' cannot be referenced in current location.
class F extends C { constructor(public z: number) { super("hello", this.z) } } // first param type
~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~
!!! Argument of type 'string' is not assignable to parameter of type 'number'.
~~~~
!!! 'this' cannot be referenced in current location.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
var test: I1<string>;
test("expects boolean instead of string"); // should not error - "test" should not expect a boolean
test(true); // should error - string expected
~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~
!!! Argument of type 'boolean' is not assignable to parameter of type 'string'.
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
// BUG 822524
var r = x.foo(1); // no error
var r2 = x.foo(''); // error
~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type 'string' is not assignable to parameter of type 'number'.

Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

// Ok to go down the chain, but error to try to climb back up
(new Chain(new A)).then(a => new B).then(b => new C).then(c => new B).then(b => new A);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~
!!! Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
var s: S;
// Ok to go down the chain, but error to climb up the chain
(new Chain(t)).then(tt => s).then(ss => t);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~
!!! Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'.

// But error to try to climb up the chain
(new Chain(s)).then(ss => t);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~
!!! Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'.

// Staying at T or S should be fine
(new Chain(t)).then(tt => t).then(tt => t).then(tt => t);
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/constructorOverloads1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
var f1 = new Foo("hey");
var f2 = new Foo(0);
var f3 = new Foo(f1);
~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type 'Foo' is not assignable to parameter of type 'number'.
var f4 = new Foo([f1,f2,f3]);
~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~
!!! Argument of type 'unknown[]' is not assignable to parameter of type 'number'.

f1.bar1();
f1.bar2();
Expand Down
5 changes: 3 additions & 2 deletions tests/baselines/reference/contextualTyping30.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
==== tests/cases/compiler/contextualTyping30.ts (1 errors) ====
function foo(param:number[]){}; foo([1, "a"]);
~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~
!!! Argument of type '{}[]' is not assignable to parameter of type 'number[]'.
!!! Type '{}' is not assignable to type 'number'.
5 changes: 3 additions & 2 deletions tests/baselines/reference/contextualTyping33.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
==== tests/cases/compiler/contextualTyping33.ts (1 errors) ====
function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
!!! Type '{}' is not assignable to type '{ (): number; (i: number): number; }'.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// errors on all 3 lines, bug was that r5 was the only line with errors
var f = (x: number) => { return x.toFixed() };
var r5 = _.forEach<number>(c2, f);
~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~
!!! Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.
var r6 = _.forEach<number>(c2, (x) => { return x.toFixed() });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
f({}); // Ok
f(obj1); // Ok
f(obj2); // Error - indexer doesn't match
~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~
!!! Argument of type '{ x: string; }' is not assignable to parameter of type '{ [x: string]: string; }'.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var n: number = f(4);
n = f();
var s: string = f('');
~~~~~
!!! Supplied parameters do not match any signature of call target.
~~
!!! Argument of type 'string' is not assignable to parameter of type 'number'.
s = f();
~
!!! Type 'number' is not assignable to type 'string'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
==== tests/cases/conformance/externalModules/foo_1.ts (1 errors) ====
import foo = require("./foo_0");
var x = new foo(true); // Should error
~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
~~~~
!!! Argument of type 'boolean' is not assignable to parameter of type '{ a: string; b: number; }'.
var y = new foo({a: "test", b: 42}); // Should be OK
var z: number = y.test.b;
==== tests/cases/conformance/externalModules/foo_0.ts (0 errors) ====
Expand Down
Loading