Skip to content

Report error on method name for chained method calls #31414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 22, 2019
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
25 changes: 20 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21247,7 +21247,8 @@ namespace ts {
reorderCandidates(signatures, candidates);
if (!candidates.length) {
if (reportErrors) {
diagnostics.add(createDiagnosticForNode(node, Diagnostics.Call_target_does_not_contain_any_signatures));
const errorNode = getCallErrorNode(node);
diagnostics.add(createDiagnosticForNode(errorNode, Diagnostics.Call_target_does_not_contain_any_signatures));
}
return resolveErrorCall(node);
}
Expand Down Expand Up @@ -21325,31 +21326,45 @@ namespace ts {
// If candidate is undefined, it means that no candidates had a suitable arity. In that case,
// skip the checkApplicableSignature check.
if (reportErrors) {
const errorNode = getCallErrorNode(node);

if (candidateForArgumentError) {
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, CheckMode.Normal, /*reportErrors*/ true);
}
else if (candidateForArgumentArityError) {
diagnostics.add(getArgumentArityError(node, [candidateForArgumentArityError], args));
diagnostics.add(getArgumentArityError(errorNode, [candidateForArgumentArityError], args));
}
else if (candidateForTypeArgumentError) {
checkTypeArguments(candidateForTypeArgumentError, (node as CallExpression | TaggedTemplateExpression | JsxOpeningLikeElement).typeArguments!, /*reportErrors*/ true, fallbackError);
}
else {
const signaturesWithCorrectTypeArgumentArity = filter(signatures, s => hasCorrectTypeArgumentArity(s, typeArguments));
if (signaturesWithCorrectTypeArgumentArity.length === 0) {
diagnostics.add(getTypeArgumentArityError(node, signatures, typeArguments!));
diagnostics.add(getTypeArgumentArityError(errorNode, signatures, typeArguments!));
}
else if (!isDecorator) {
diagnostics.add(getArgumentArityError(node, signaturesWithCorrectTypeArgumentArity, args));
diagnostics.add(getArgumentArityError(errorNode, signaturesWithCorrectTypeArgumentArity, args));
}
else if (fallbackError) {
diagnostics.add(createDiagnosticForNode(node, fallbackError));
diagnostics.add(createDiagnosticForNode(errorNode, fallbackError));
}
}
}

return produceDiagnostics || !args ? resolveErrorCall(node) : getCandidateForOverloadFailure(node, candidates, args, !!candidatesOutArray);

function getCallErrorNode(node: CallLikeExpression): Node {
if (isCallExpression(node)) {
if (isPropertyAccessExpression(node.expression)) {
return node.expression.name;
}
else {
return node.expression;
}
}
return node;
}

function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>, signatureHelpTrailingComma = false) {
candidateForArgumentError = undefined;
candidateForArgumentArityError = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ tests/cases/compiler/arityErrorRelatedSpanBindingPattern.ts(7,1): error TS2554:
function bar(a, b, [c]): void {}

foo("", 0);
~~~~~~~~~~
~~~
!!! error TS2554: Expected 3 arguments, but got 2.
!!! related TS6211 tests/cases/compiler/arityErrorRelatedSpanBindingPattern.ts:1:20: An argument matching this binding pattern was not provided.

bar("", 0);
~~~~~~~~~~
~~~
!!! error TS2554: Expected 3 arguments, but got 2.
!!! related TS6211 tests/cases/compiler/arityErrorRelatedSpanBindingPattern.ts:3:20: An argument matching this binding pattern was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/baseCheck.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tests/cases/compiler/baseCheck.ts(26,9): error TS2304: Cannot find name 'x'.
}

class D extends C { constructor(public z: number) { super(this.z) } } // too few params
~~~~~~~~~~~~~
~~~~~
!!! error TS2554: Expected 2 arguments, but got 1.
!!! related TS6210 tests/cases/compiler/baseCheck.ts:1:34: An argument for 'y' was not provided.
~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ tests/cases/compiler/blockScopedSameNameFunctionDeclarationES5.ts(16,1): error T
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/blockScopedSameNameFunctionDeclarationES5.ts:1:14: An argument for 'a' was not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ tests/cases/compiler/blockScopedSameNameFunctionDeclarationES6.ts(16,1): error T
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/blockScopedSameNameFunctionDeclarationES6.ts:1:14: An argument for 'a' was not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ tests/cases/compiler/blockScopedSameNameFunctionDeclarationStrictES5.ts(17,1): e
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/blockScopedSameNameFunctionDeclarationStrictES5.ts:2:14: An argument for 'a' was not provided.
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/blockScopedSameNameFunctionDeclarationStrictES5.ts:2:14: An argument for 'a' was not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ tests/cases/compiler/blockScopedSameNameFunctionDeclarationStrictES6.ts(17,1): e
}
foo(10);
foo(); // not ok
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/blockScopedSameNameFunctionDeclarationStrictES6.ts:2:14: An argument for 'a' was not provided.
}
foo(10);
foo(); // not ok - needs number
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/blockScopedSameNameFunctionDeclarationStrictES6.ts:2:14: An argument for 'a' was not provided.
2 changes: 1 addition & 1 deletion tests/baselines/reference/callOverload.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tests/cases/conformance/expressions/functionCalls/callOverload.ts(11,10): error
!!! error TS2554: Expected 2 arguments, but got 4.
withRest('a', ...n); // no error
withRest();
~~~~~~~~~~
~~~~~~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callOverload.ts:3:27: An argument for 'a' was not provided.
withRest(...n);
Expand Down
28 changes: 14 additions & 14 deletions tests/baselines/reference/callWithMissingVoid.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(16,1): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(19,1): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(22,1): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(16,6): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(19,10): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(22,8): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(35,31): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(36,35): error TS2554: Expected 1 arguments, but got 0.
tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(37,33): error TS2554: Expected 1 arguments, but got 0.
Expand Down Expand Up @@ -28,19 +28,19 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,1):

declare const xAny: X<any>;
xAny.f() // error, any still expects an argument
~~~~~~~~
~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea was that the argument list was supposed to be included in the range.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, just saw your comment in the PR.

!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided.

declare const xUnknown: X<unknown>;
xUnknown.f() // error, unknown still expects an argument
~~~~~~~~~~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided.

declare const xNever: X<never>;
xNever.f() // error, never still expects an argument
~~~~~~~~~~
~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:3:7: An argument for 't' was not provided.

Expand All @@ -56,15 +56,15 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,1):
new MyPromise<void>(resolve => resolve()); // no error
new MyPromise<void | number>(resolve => resolve()); // no error
new MyPromise<any>(resolve => resolve()); // error, `any` arguments cannot be omitted
~~~~~~~~~
~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
new MyPromise<unknown>(resolve => resolve()); // error, `unknown` arguments cannot be omitted
~~~~~~~~~
~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.
new MyPromise<never>(resolve => resolve()); // error, `never` arguments cannot be omitted
~~~~~~~~~
~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:28:38: An argument for 'value' was not provided.

Expand All @@ -78,7 +78,7 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,1):
a(4, "hello"); // ok
a(4, "hello", void 0); // ok
a(4); // not ok
~~~~
~
!!! error TS2554: Expected 3 arguments, but got 1.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:42:23: An argument for 'y' was not provided.

Expand All @@ -88,15 +88,15 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,1):

b(4, "hello", void 0, 2); // ok
b(4, "hello"); // not ok
~~~~~~~~~~~~~
~
!!! error TS2554: Expected 4 arguments, but got 2.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:50:34: An argument for 'z' was not provided.
b(4, "hello", void 0); // not ok
~~~~~~~~~~~~~~~~~~~~~
~
!!! error TS2554: Expected 4 arguments, but got 3.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:50:43: An argument for 'what' was not provided.
b(4); // not ok
~~~~
~
!!! error TS2554: Expected 4 arguments, but got 1.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:50:23: An argument for 'y' was not provided.

Expand All @@ -117,7 +117,7 @@ tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts(75,1):
...args: TS): void;

call((x: number, y: number) => x + y) // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS2554: Expected 3 arguments, but got 1.
!!! related TS6210 tests/cases/conformance/expressions/functionCalls/callWithMissingVoid.ts:73:5: An argument for 'args' was not provided.
call((x: number, y: number) => x + y, 4, 2) // ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tests/cases/conformance/salsa/second.ts(17,15): error TS2345: Argument of type '
class Sql extends Wagon {
constructor() {
super(); // error: not enough arguments
~~~~~~~
~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/conformance/salsa/first.js:5:16: An argument for 'numberOxen' was not provided.
this.foonly = 12
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/derivedTypeCallingBaseImplWithOptionalParams.ts(13,1): error TS2554: Expected 1 arguments, but got 0.
tests/cases/compiler/derivedTypeCallingBaseImplWithOptionalParams.ts(13,3): error TS2554: Expected 1 arguments, but got 0.


==== tests/cases/compiler/derivedTypeCallingBaseImplWithOptionalParams.ts (1 errors) ====
Expand All @@ -15,6 +15,6 @@ tests/cases/compiler/derivedTypeCallingBaseImplWithOptionalParams.ts(13,1): erro

var y: MyClass = new MyClass();
y.myMethod(); // error
~~~~~~~~~~~~
~~~~~~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/derivedTypeCallingBaseImplWithOptionalParams.ts:5:14: An argument for 'myList' was not provided.
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall11.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/cases/compiler/functionCall11.ts(6,15): error TS2554: Expected 1-2 argumen
foo('foo', 1);
foo('foo');
foo();
~~~~~
~~~
!!! error TS2554: Expected 1-2 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall11.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall12.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/cases/compiler/functionCall12.ts(7,15): error TS2345: Argument of type '3'
foo('foo', 1);
foo('foo');
foo();
~~~~~
~~~
!!! error TS2554: Expected 1-3 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall12.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall13.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tests/cases/compiler/functionCall13.ts(5,5): error TS2345: Argument of type '1'
foo('foo', 1);
foo('foo');
foo();
~~~~~
~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall13.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall16.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tests/cases/compiler/functionCall16.ts(6,5): error TS2345: Argument of type '1'
foo('foo');
foo('foo', 'bar');
foo();
~~~~~
~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall16.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall17.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tests/cases/compiler/functionCall17.ts(6,12): error TS2345: Argument of type '1'
!!! error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
foo('foo');
foo();
~~~~~
~~~
!!! error TS2555: Expected at least 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall17.ts:1:14: An argument for 'a' was not provided.
foo(1, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall18.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/compiler/functionCall18.ts(4,1): error TS2554: Expected 2 arguments,
declare function foo<T>(a: T, b: T);
declare function foo(a: {});
foo<string>("hello");
~~~~~~~~~~~~~~~~~~~~
~~~
!!! error TS2554: Expected 2 arguments, but got 1.
!!! related TS6210 tests/cases/compiler/functionCall18.ts:2:31: An argument for 'b' was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall6.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tests/cases/compiler/functionCall6.ts(5,1): error TS2554: Expected 1 arguments,
~~~~~
!!! error TS2554: Expected 1 arguments, but got 2.
foo();
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall6.ts:1:14: An argument for 'a' was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/functionCall7.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests/cases/compiler/functionCall7.ts(7,1): error TS2554: Expected 1 arguments,
~
!!! error TS2345: Argument of type '4' is not assignable to parameter of type 'c1'.
foo();
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionCall7.ts:2:14: An argument for 'a' was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/functionOverloads29.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/compiler/functionOverloads29.ts(4,9): error TS2554: Expected 1 argum
function foo(bar:number):number;
function foo(bar:any):any{ return bar }
var x = foo();
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionOverloads29.ts:1:14: An argument for 'bar' was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/functionOverloads34.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/compiler/functionOverloads34.ts(4,9): error TS2554: Expected 1 argum
function foo(bar:{a:boolean;}):number;
function foo(bar:{a:any;}):any{ return bar }
var x = foo();
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionOverloads34.ts:1:14: An argument for 'bar' was not provided.

2 changes: 1 addition & 1 deletion tests/baselines/reference/functionOverloads37.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/compiler/functionOverloads37.ts(4,9): error TS2554: Expected 1 argum
function foo(bar:{a:boolean;}[]):number;
function foo(bar:{a:any;}[]):any{ return bar }
var x = foo();
~~~~~
~~~
!!! error TS2554: Expected 1 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionOverloads37.ts:1:14: An argument for 'bar' was not provided.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ tests/cases/compiler/functionParameterArityMismatch.ts(14,22): error TS2554: Exp
declare function f1(a: number);
declare function f1(a: number, b: number, c: number);
f1();
~~~~
~~
!!! error TS2554: Expected 1-3 arguments, but got 0.
!!! related TS6210 tests/cases/compiler/functionParameterArityMismatch.ts:1:21: An argument for 'a' was not provided.
f1(1, 2);
~~~~~~~~
~~
!!! error TS2575: No overload expects 2 arguments, but overloads do exist that expect either 1 or 3 arguments.
f1(1, 2, 3, 4);
~
Expand All @@ -26,13 +26,13 @@ tests/cases/compiler/functionParameterArityMismatch.ts(14,22): error TS2554: Exp
declare function f2(a: number, b: number, c: number, d: number);
declare function f2(a: number, b: number, c: number, d: number, e: number, f: number);
f2(1);
~~~~~
~~
!!! error TS2575: No overload expects 1 arguments, but overloads do exist that expect either 0 or 2 arguments.
f2(1, 2, 3);
~~~~~~~~~~~
~~
!!! error TS2575: No overload expects 3 arguments, but overloads do exist that expect either 2 or 4 arguments.
f2(1, 2, 3, 4, 5);
~~~~~~~~~~~~~~~~~
~~
!!! error TS2575: No overload expects 5 arguments, but overloads do exist that expect either 4 or 6 arguments.
f2(1, 2, 3, 4, 5, 6, 7);
~
Expand Down
Loading