Skip to content

Commit 6051fc1

Browse files
committed
move to invocationErrorDetails
1 parent d00f2b5 commit 6051fc1

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26049,7 +26049,7 @@ namespace ts {
2604926049
return true;
2605026050
}
2605126051

26052-
function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
26052+
function invocationErrorDetails(errorTarget: Node, apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
2605326053
let errorInfo: DiagnosticMessageChain | undefined;
2605426054
const isCall = kind === SignatureKind.Call;
2605526055
const awaitedType = getAwaitedType(apparentType);
@@ -26118,6 +26118,15 @@ namespace ts {
2611826118
typeToString(apparentType)
2611926119
);
2612026120
}
26121+
26122+
// Diagnose get accessors incorrectly called as functions
26123+
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
26124+
const { resolvedSymbol } = getNodeLinks(errorTarget);
26125+
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
26126+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
26127+
}
26128+
}
26129+
2612126130
return {
2612226131
messageChain: chainDiagnosticMessages(
2612326132
errorInfo,
@@ -26127,21 +26136,10 @@ namespace ts {
2612726136
};
2612826137
}
2612926138
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-
}
26139+
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(errorTarget, apparentType, kind);
26140+
const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
26141+
if (relatedInfo) {
26142+
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
2614526143
}
2614626144
if (isCallExpression(errorTarget.parent)) {
2614726145
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
@@ -26242,7 +26240,7 @@ namespace ts {
2624226240

2624326241
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
2624426242
if (!callSignatures.length) {
26245-
const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
26243+
const errorDetails = invocationErrorDetails(node.expression, apparentType, SignatureKind.Call);
2624626244
const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
2624726245
const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
2624826246
if (errorDetails.relatedMessage) {

0 commit comments

Comments
 (0)