Skip to content

Always emit diagnostic when a call expression can be fixed by adding a semicolon #27669

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 1 commit into from
Nov 12, 2018
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20046,7 +20046,7 @@ namespace ts {
}
else {
let relatedInformation: DiagnosticRelatedInformation | undefined;
if (node.arguments.length === 1 && isTypeAssertion(first(node.arguments))) {
if (node.arguments.length === 1) {
const text = getSourceFileOfNode(node).text;
if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) {
relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.It_is_highly_likely_that_you_are_missing_a_semicolon);
Expand Down
39 changes: 39 additions & 0 deletions tests/baselines/reference/betterErrorForAccidentalCall.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
tests/cases/compiler/betterErrorForAccidentalCall.ts(3,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
tests/cases/compiler/betterErrorForAccidentalCall.ts(5,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
tests/cases/compiler/betterErrorForAccidentalCall.ts(7,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
tests/cases/compiler/betterErrorForAccidentalCall.ts(10,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
tests/cases/compiler/betterErrorForAccidentalCall.ts(13,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.


==== tests/cases/compiler/betterErrorForAccidentalCall.ts (5 errors) ====
declare function foo(): string;

foo()(1 as number).toString();
~~~~~~~~~~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.

foo() (1 as number).toString();
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.

foo()
~~~~~
(1 as number).toString();
~~~~~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentalCall.ts:7:1: It is highly likely that you are missing a semicolon.

foo()
~~~~~
(1 + 2).toString();
~~~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentalCall.ts:10:1: It is highly likely that you are missing a semicolon.

foo()
~~~~~
(<number>1).toString();
~~~~~~~~~~~~~~~
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentalCall.ts:13:1: It is highly likely that you are missing a semicolon.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [betterErrorForAccidentallyCallingTypeAssertionExpressions.ts]
//// [betterErrorForAccidentalCall.ts]
declare function foo(): string;

foo()(1 as number).toString();
Expand All @@ -8,16 +8,16 @@ foo() (1 as number).toString();
foo()
(1 as number).toString();

foo()
(1 as number).toString();
foo()
(1 + 2).toString();

foo()
foo()
(<number>1).toString();


//// [betterErrorForAccidentallyCallingTypeAssertionExpressions.js]
foo()(1).toString();
//// [betterErrorForAccidentalCall.js]
foo()(1).toString();
foo()(1).toString();
foo()(1).toString();
foo()(1 + 2).toString();
foo()(1).toString();
25 changes: 25 additions & 0 deletions tests/baselines/reference/betterErrorForAccidentalCall.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/compiler/betterErrorForAccidentalCall.ts ===
declare function foo(): string;
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))

foo()(1 as number).toString();
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))

foo() (1 as number).toString();
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))

foo()
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))

(1 as number).toString();

foo()
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))

(1 + 2).toString();

foo()
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))

(<number>1).toString();

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=== tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts ===
=== tests/cases/compiler/betterErrorForAccidentalCall.ts ===
declare function foo(): string;
>foo : () => string

Expand Down Expand Up @@ -34,22 +34,23 @@ foo()
>1 : 1
>toString : any

foo()
>foo() (1 as number).toString() : any
>foo() (1 as number).toString : any
>foo() (1 as number) : any
foo()
>foo() (1 + 2).toString() : any
>foo() (1 + 2).toString : any
>foo() (1 + 2) : any
>foo() : string
>foo : () => string

(1 as number).toString();
>1 as number : number
(1 + 2).toString();
>1 + 2 : number
>1 : 1
>2 : 2
>toString : any

foo()
>foo() (<number>1).toString() : any
>foo() (<number>1).toString : any
>foo() (<number>1) : any
foo()
>foo() (<number>1).toString() : any
>foo() (<number>1).toString : any
>foo() (<number>1) : any
>foo() : string
>foo : () => string

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ foo() (1 as number).toString();
foo()
(1 as number).toString();

foo()
(1 as number).toString();
foo()
(1 + 2).toString();

foo()
foo()
(<number>1).toString();