Skip to content

Commit

Permalink
replace the original not-callable error
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbandes committed Apr 19, 2020
1 parent d00a5c9 commit d00f2b5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 47 deletions.
41 changes: 21 additions & 20 deletions src/compiler/checker.ts
Expand Up @@ -25851,24 +25851,14 @@ namespace ts {
error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
}
else {
const relatedInformation: DiagnosticRelatedInformation[] = [];
if (node.arguments.length === 0) {
// Diagnose get accessors incorrectly called as functions
const { resolvedSymbol } = getNodeLinks(node.expression);
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
relatedInformation.push(
createDiagnosticForNode(node.expression, Diagnostics._0_is_a_get_accessor_did_you_mean_to_use_it_without, getTextOfNode(node.expression)),
createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol))
);
}
}
else if (node.arguments.length === 1) {
let relatedInformation: DiagnosticRelatedInformation | undefined;
if (node.arguments.length === 1) {
const text = getSourceFileOfNode(node).text;
if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) {
relatedInformation.push(createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon));
relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.Are_you_missing_a_semicolon);
}
}
invocationError(node.expression, apparentType, SignatureKind.Call, ...relatedInformation);
invocationError(node.expression, apparentType, SignatureKind.Call, relatedInformation);
}
return resolveErrorCall(node);
}
Expand Down Expand Up @@ -26136,19 +26126,30 @@ namespace ts {
relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined,
};
}
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, ...relatedInformation: DiagnosticRelatedInformation[]) {
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
if (relatedInfo) {
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
let diagnostic;
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
// Diagnose get accessors incorrectly called as functions
const { resolvedSymbol } = getNodeLinks(errorTarget);
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
diagnostic = createDiagnosticForNode(errorTarget, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
addRelatedInfo(diagnostic, createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol)));
}
}
if (!diagnostic) {
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
if (relatedInfo) {
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
}
}
if (isCallExpression(errorTarget.parent)) {
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
diagnostic.start = start;
diagnostic.length = length;
}
diagnostics.add(diagnostic);
invocationErrorRecovery(apparentType, kind, addRelatedInfo(diagnostic, ...relatedInformation));
invocationErrorRecovery(apparentType, kind, relatedInformation ? addRelatedInfo(diagnostic, relatedInformation) : diagnostic);
}

function invocationErrorRecovery(apparentType: Type, kind: SignatureKind, diagnostic: Diagnostic) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/diagnosticMessages.json
Expand Up @@ -4384,7 +4384,7 @@
"category": "Error",
"code": 6231
},
"'{0}' is a 'get' accessor; did you mean to use it without '()'?": {
"This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?": {
"category": "Message",
"code": 6232
},
Expand Down Expand Up @@ -5645,7 +5645,7 @@
"category": "Message",
"code": 95116
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
"code": 18004
Expand Down
@@ -1,5 +1,4 @@
tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): error TS2349: This expression is not callable.
Type 'Number' has no call signatures.
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 '()'?


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

@@ -1,11 +1,9 @@
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(19,16): error TS2349: This expression is not callable.
Type 'Number' has no call signatures.
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 '()'?
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(26,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(29,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts(41,16): error TS2349: This expression is not callable.
Type 'String' has no call signatures.
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 '()'?


==== tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts (6 errors) ====
Expand Down Expand Up @@ -33,9 +31,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn
r.y = 4;
var r6 = d.y(); // error
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'Number' has no call signatures.
!!! 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 '()'?
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:4:13: 'y' is declared here.

}
Expand Down Expand Up @@ -64,8 +60,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn
r.y = '';
var r6 = d.y(); // error
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'String' has no call signatures.
!!! 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 '()'?
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts:26:13: 'y' is declared here.
}
14 changes: 4 additions & 10 deletions tests/baselines/reference/instancePropertyInClassType.errors.txt
@@ -1,11 +1,9 @@
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(4,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(7,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(17,16): error TS2349: This expression is not callable.
Type 'Number' has no call signatures.
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 '()'?
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(24,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(27,13): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts(37,16): error TS2349: This expression is not callable.
Type 'String' has no call signatures.
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 '()'?


==== tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts (6 errors) ====
Expand All @@ -31,9 +29,7 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t
r.y = 4;
var r6 = c.y(); // error
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'Number' has no call signatures.
!!! 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 '()'?
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:4:13: 'y' is declared here.

}
Expand All @@ -60,8 +56,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t
r.y = '';
var r6 = c.y(); // error
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'String' has no call signatures.
!!! 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 '()'?
!!! message TS6232: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?
!!! related TS2728 tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts:24:13: 'y' is declared here.
}

0 comments on commit d00f2b5

Please sign in to comment.