Skip to content
Closed
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
36 changes: 28 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3629,8 +3629,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.
// 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;
Expand Down Expand Up @@ -3693,15 +3693,23 @@ module ts {
return result;
}

function isApplicableSignature(node: CallExpression, signature: Signature, relation: Map<boolean>, excludeArgument: boolean[]) {
function checkSignatureIsApplicable(node: CallExpression, signature: Signature, relation: Map<boolean>, excludeArgument: boolean[], errMessage?: DiagnosticMessage) {
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 ?
getStringLiteralType(<LiteralExpression>arg) :
checkExpression(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
if (!isTypeRelatedTo(argType, paramType, relation)) return false;

// When errMessage is given, we actually want to error on a type mismatch.
var typeIsRelated = errMessage ?
checkTypeRelatedTo(argType, paramType, relation, node, /* chainedMessage */ errMessage, /* terminalMessage */ errMessage) :
isTypeRelatedTo(argType, paramType, relation);

if (!typeIsRelated) {
return false;
}
}
}
return true;
Expand All @@ -3724,7 +3732,7 @@ module ts {
}
var relation = candidates.length === 1 ? assignableRelation : subtypeRelation;
while (true) {
for (var i = 0; i < candidates.length; i++) {
for (var i = 0, n = candidates.length; i < n; i++) {
while (true) {
var candidate = candidates[i];
if (candidate.typeParameters) {
Expand All @@ -3733,18 +3741,30 @@ module ts {
inferTypeArguments(candidate, args, excludeArgument);
candidate = getSignatureInstantiation(candidate, typeArguments);
}
if (!isApplicableSignature(node, candidate, relation, excludeArgument)) break;

// On the last signature, we supply 'checkSignatureIsApplicable' with an error message
// to make it elaborate on any assignment compatibility issues we may run into.
var errMsg = (relation === assignableRelation && i === n - 1) ?
Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target :
undefined;

if (!checkSignatureIsApplicable(node, candidate, relation, excludeArgument, errMsg)) {
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);

return checkErrorCall(node);
}

Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/arrayAssignmentTest3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
var xx = new a(null, 7, new B());
~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'concat' is missing in type 'B'.


Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
foo(arr); // Error because of no contextual type
~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type '{}' is not assignable to type 'IAnimal':
!!! Property 'name' is missing in type '{}'.
bar(arr); // Error because of no contextual type
~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.
!!! Index signatures are incompatible:
!!! Type '{}' is not assignable to type 'IAnimal'.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
fn((a, b) => true);
~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'x' is missing in type '{}'.
fn(function (a, b) { return true; })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/assignmentCompatBug5.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
foo1({ b: 5 });
~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! 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.
!!! 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.
!!! Types of parameters 's' and 'n' are incompatible:
!!! Type 'string' is not assignable to type 'number'.
foo3((n) => { return; });
~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type 'void' is not assignable to type 'number'.


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
foo({ id: 1234, name: false }); // Error, name of wrong type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! 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.
!!! Supplied parameters do not match any signature of call target.
!!! Property 'id' is missing in type '{ name: string; }'.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
Biz(new Foo());
~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Index signature is missing in type 'Foo'.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
fn({});
~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'apply' is missing in type '{}'.


// Should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
fn({});
~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'call' is missing in type '{}'.


// Should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,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.
!!! Supplied parameters do not match any signature of call target.
!!! Type 'B' is not assignable to type 'C'.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
(new Chain(t)).then(tt => s).then(ss => t);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type 'T' is not assignable to type '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.
!!! Type 'T' is not assignable to type 'S'.

// Staying at T or S should be fine
(new Chain(t)).then(tt => t).then(tt => t).then(tt => t);
Expand Down
3 changes: 2 additions & 1 deletion 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.
!!! Supplied parameters do not match any signature of call target.
!!! Type '{}' is not assignable to type 'number'.
3 changes: 2 additions & 1 deletion 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.
!!! Supplied parameters do not match any signature of call target.
!!! Type '{}' is not assignable to type '{ (): number; (i: number): number; }'.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
var r5 = _.forEach<number>(c2, f);
~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type 'string' is not assignable to type 'Date':
!!! Property 'toDateString' is missing in type 'String'.
var r6 = _.forEach<number>(c2, (x) => { return x.toFixed() });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type 'string' is not assignable to type 'Date':
!!! Property 'toDateString' is missing in type 'String'.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
f(obj1); // Ok
f(obj2); // Error - indexer doesn't match
~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.
!!! Index signature is missing in type '{ x: string; }'.
1 change: 1 addition & 0 deletions tests/baselines/reference/functionCall7.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
foo(4);
~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'a' is missing in type 'Number'.
foo();
~~~~~
!!! Supplied parameters do not match any signature of call target.
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/functionOverloads40.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
var x = foo([{a:'bar'}]);
~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type '{ a: string; }' is not assignable to type '{ a: boolean; }':
!!! Types of property 'a' are incompatible:
!!! Type 'string' is not assignable to type 'boolean'.

2 changes: 2 additions & 0 deletions tests/baselines/reference/functionOverloads41.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
var x = foo([{}]);
~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type '{}' is not assignable to type '{ a: boolean; }':
!!! Property 'a' is missing in type '{}'.

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
var r4 = foo<Date, Date>(1); // error
~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'toDateString' is missing in type 'Number'.
var r5 = foo<Date, Date>(new Date()); // no error
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
var r2 = foo(arg2); // error
~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'cb' are incompatible:
!!! Type 'new <T>(x: T, y: T) => string' is not assignable to type 'new (t: any) => string'.
var arg3: { cb: new (x: string, y: number) => string };
var r3 = foo(arg3); // error
~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'cb' are incompatible:
!!! Type 'new (x: string, y: number) => string' is not assignable to type 'new (t: string) => string'.

function foo2<T, U>(arg: { cb: new(t: T, t2: T) => U }) {
return new arg.cb(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
var r2 = foo({ cb: <T>(x: T, y: T) => '' }); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'cb' are incompatible:
!!! Type '<T>(x: T, y: T) => string' is not assignable to type '(t: any) => string'.
var r3 = foo({ cb: (x: string, y: number) => '' }); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'cb' are incompatible:
!!! Type '(x: string, y: number) => string' is not assignable to type '(t: string) => string'.

function foo2<T, U>(arg: { cb: (t: T, t2: T) => U }) {
return arg.cb(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
var r7 = foo2((a: T) => a, (b: T) => b); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of parameters 'a' and 'x' are incompatible:
!!! Type 'T' is not assignable to type 'Date'.
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
}

Expand All @@ -42,4 +44,5 @@

var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.
!!! Type 'F' is not assignable to type 'E'.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
var x2 = foo<number>({ x: 3, y: "" }, 4);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'y' are incompatible:
!!! Type 'string' is not assignable to type 'number'.
var x3 = foo<string>({ x: 3, y: "" }, 4);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'x' are incompatible:
!!! Type 'number' is not assignable to type 'string'.
var x4 = foo<number>({ x: "", y: 4 }, "");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'x' are incompatible:
!!! Type 'string' is not assignable to type 'number'.
var x5 = foo<string>({ x: "", y: 4 }, "");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'y' are incompatible:
!!! Type 'number' is not assignable to type 'string'.
6 changes: 5 additions & 1 deletion tests/baselines/reference/genericCombinators2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
var r5a = _.map<number, string, Date>(c2, (x, y) => { return x.toFixed() });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type 'string' is not assignable to type 'Date':
!!! Property 'toDateString' is missing in type 'String'.
var r5b = _.map<number, string, Date>(c2, rf1);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.
!!! Type 'string' is not assignable to type 'Date':
!!! Property 'toDateString' is missing in type 'String'.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
x.f({s: 1})
~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 's' are incompatible:
!!! Type 'number' is not assignable to type 'string'.

3 changes: 2 additions & 1 deletion tests/baselines/reference/genericRestArgs.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
var a2Gb = makeArrayG<any>(1, "");
var a2Gc = makeArrayG<any[]>(1, ""); // error
~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Supplied parameters do not match any signature of call target.
!!! Property 'concat' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
this.test([1, 2, "hi", 5]); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Type '{}' is not assignable to type 'string'.
}
}
4 changes: 4 additions & 0 deletions tests/baselines/reference/incompatibleTypes.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
if1(c1);
~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Types of property 'p1' are incompatible:
!!! Type '() => string' is not assignable to type '(s: string) => number':
!!! Type 'string' is not assignable to type 'number'.


function of1(n: { a: { a: string; }; b: string; }): number;
Expand All @@ -72,6 +75,7 @@
of1({ e: 0, f: 0 });
~~~~~~~~~~~~~~~~~~~
!!! Supplied parameters do not match any signature of call target.
!!! Property 'c' is missing in type '{ e: number; f: number; }'.

interface IMap {
[key:string]:string;
Expand Down
Loading