Skip to content

Commit d00f2b5

Browse files
committed
replace the original not-callable error
1 parent d00a5c9 commit d00f2b5

File tree

5 files changed

+33
-47
lines changed

5 files changed

+33
-47
lines changed

src/compiler/checker.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25851,24 +25851,14 @@ namespace ts {
2585125851
error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
2585225852
}
2585325853
else {
25854-
const relatedInformation: DiagnosticRelatedInformation[] = [];
25855-
if (node.arguments.length === 0) {
25856-
// Diagnose get accessors incorrectly called as functions
25857-
const { resolvedSymbol } = getNodeLinks(node.expression);
25858-
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
25859-
relatedInformation.push(
25860-
createDiagnosticForNode(node.expression, Diagnostics._0_is_a_get_accessor_did_you_mean_to_use_it_without, getTextOfNode(node.expression)),
25861-
createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol))
25862-
);
25863-
}
25864-
}
25865-
else if (node.arguments.length === 1) {
25854+
let relatedInformation: DiagnosticRelatedInformation | undefined;
25855+
if (node.arguments.length === 1) {
2586625856
const text = getSourceFileOfNode(node).text;
2586725857
if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) {
25868-
relatedInformation.push(createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon));
25858+
relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon);
2586925859
}
2587025860
}
25871-
invocationError(node.expression, apparentType, SignatureKind.Call, ...relatedInformation);
25861+
invocationError(node.expression, apparentType, SignatureKind.Call, relatedInformation);
2587225862
}
2587325863
return resolveErrorCall(node);
2587425864
}
@@ -26136,19 +26126,30 @@ namespace ts {
2613626126
relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined,
2613726127
};
2613826128
}
26139-
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, ...relatedInformation: DiagnosticRelatedInformation[]) {
26140-
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
26141-
const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
26142-
if (relatedInfo) {
26143-
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
26129+
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
26130+
let diagnostic;
26131+
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
26132+
// Diagnose get accessors incorrectly called as functions
26133+
const { resolvedSymbol } = getNodeLinks(errorTarget);
26134+
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
26135+
diagnostic = createDiagnosticForNode(errorTarget, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
26136+
addRelatedInfo(diagnostic, createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol)));
26137+
}
26138+
}
26139+
if (!diagnostic) {
26140+
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
26141+
diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
26142+
if (relatedInfo) {
26143+
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
26144+
}
2614426145
}
2614526146
if (isCallExpression(errorTarget.parent)) {
2614626147
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
2614726148
diagnostic.start = start;
2614826149
diagnostic.length = length;
2614926150
}
2615026151
diagnostics.add(diagnostic);
26151-
invocationErrorRecovery(apparentType, kind, addRelatedInfo(diagnostic, ...relatedInformation));
26152+
invocationErrorRecovery(apparentType, kind, relatedInformation ? addRelatedInfo(diagnostic, relatedInformation) : diagnostic);
2615226153
}
2615326154

2615426155
function invocationErrorRecovery(apparentType: Type, kind: SignatureKind, diagnostic: Diagnostic) {

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,7 +4384,7 @@
43844384
"category": "Error",
43854385
"code": 6231
43864386
},
4387-
"'{0}' is a 'get' accessor; did you mean to use it without '()'?": {
4387+
"This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?": {
43884388
"category": "Message",
43894389
"code": 6232
43904390
},
@@ -5645,7 +5645,7 @@
56455645
"category": "Message",
56465646
"code": 95116
56475647
},
5648-
5648+
56495649
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
56505650
"category": "Error",
56515651
"code": 18004
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: This expression is not callable.
2-
Type 'Number' has no call signatures.
1+
tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
32

43

54
==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ====
@@ -10,9 +9,7 @@ tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: Th
109
function test24554(x: Test24554) {
1110
return x.property();
1211
~~~~~~~~
13-
!!! error TS2349: This expression is not callable.
14-
!!! error TS2349: Type 'Number' has no call signatures.
15-
!!! related TS6232 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:6:12: 'x.property' is a 'get' accessor; did you mean to use it without '()'?
12+
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
1613
!!! related TS2728 tests/cases/compiler/accessorAccidentalCallDiagnostic.ts:3:9: 'property' is declared here.
1714
}
1815

tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
22
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3-
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): error TS2349: This expression is not callable.
4-
Type 'Number' has no call signatures.
3+
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
54
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(26,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
65
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(29,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
7-
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): error TS2349: This expression is not callable.
8-
Type 'String' has no call signatures.
6+
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
97

108

119
==== tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts (6 errors) ====
@@ -33,9 +31,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn
3331
r.y = 4;
3432
var r6 = d.y(); // error
3533
~
36-
!!! error TS2349: This expression is not callable.
37-
!!! error TS2349: Type 'Number' has no call signatures.
38-
!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:19:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'?
34+
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
3935
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:4:13: 'y' is declared here.
4036

4137
}
@@ -64,8 +60,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn
6460
r.y = '';
6561
var r6 = d.y(); // error
6662
~
67-
!!! error TS2349: This expression is not callable.
68-
!!! error TS2349: Type 'String' has no call signatures.
69-
!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:41:14: 'd.y' is a 'get' accessor; did you mean to use it without '()'?
63+
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
7064
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:26:13: 'y' is declared here.
7165
}

tests/baselines/reference/instancePropertyInClassType.errors.txt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
22
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3-
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): error TS2349: This expression is not callable.
4-
Type 'Number' has no call signatures.
3+
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
54
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(24,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
65
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(27,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
7-
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): error TS2349: This expression is not callable.
8-
Type 'String' has no call signatures.
6+
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
97

108

119
==== tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts (6 errors) ====
@@ -31,9 +29,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t
3129
r.y = 4;
3230
var r6 = c.y(); // error
3331
~
34-
!!! error TS2349: This expression is not callable.
35-
!!! error TS2349: Type 'Number' has no call signatures.
36-
!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:17:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'?
32+
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
3733
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:4:13: 'y' is declared here.
3834

3935
}
@@ -60,8 +56,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t
6056
r.y = '';
6157
var r6 = c.y(); // error
6258
~
63-
!!! error TS2349: This expression is not callable.
64-
!!! error TS2349: Type 'String' has no call signatures.
65-
!!! related TS6232 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:37:14: 'c.y' is a 'get' accessor; did you mean to use it without '()'?
59+
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
6660
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:24:13: 'y' is declared here.
6761
}

0 commit comments

Comments
 (0)