diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 897654e336..191764c92a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26324,19 +26324,18 @@ namespace ts { ); } + let headMessage = isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable; + // Diagnose get accessors incorrectly called as functions if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) { const { resolvedSymbol } = getNodeLinks(errorTarget); if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) { - errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without); + headMessage = Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without; } } return { - messageChain: chainDiagnosticMessages( - errorInfo, - isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable - ), + messageChain: chainDiagnosticMessages(errorInfo, headMessage), relatedMessage: maybeMissingAwait ? Diagnostics.Did_you_forget_to_use_await : undefined, }; } diff --git a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt index f5e0afe4bd..0b3e5df31a 100644 --- a/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt +++ b/tests/baselines/reference/accessorAccidentalCallDiagnostic.errors.txt @@ -1,4 +1,5 @@ -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(6,14): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'Number' has no call signatures. ==== tests/cases/compiler/accessorAccidentalCallDiagnostic.ts (1 errors) ==== @@ -9,7 +10,7 @@ tests/cases/compiler/accessorAccidentalCallDiagnostic.ts(6,14): message TS6232: function test24554(x: Test24554) { return x.property(); ~~~~~~~~ -!!! 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. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'Number' has no call signatures. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt index 31190afaf0..fab7ccc6e5 100644 --- a/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt +++ b/tests/baselines/reference/instancePropertiesInheritedIntoClassType.errors.txt @@ -1,9 +1,11 @@ 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): 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(19,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'Number' has no call signatures. 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): 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(41,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'String' has no call signatures. ==== tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIntoClassType.ts (6 errors) ==== @@ -31,8 +33,8 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = 4; var r6 = d.y(); // error ~ -!!! 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. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'Number' has no call signatures. } @@ -60,6 +62,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertiesInheritedIn r.y = ''; var r6 = d.y(); // error ~ -!!! 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. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'String' has no call signatures. } \ No newline at end of file diff --git a/tests/baselines/reference/instancePropertyInClassType.errors.txt b/tests/baselines/reference/instancePropertyInClassType.errors.txt index 62241900ab..2921b37568 100644 --- a/tests/baselines/reference/instancePropertyInClassType.errors.txt +++ b/tests/baselines/reference/instancePropertyInClassType.errors.txt @@ -1,9 +1,11 @@ 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): 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(17,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'Number' has no call signatures. 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): 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(37,16): message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? + Type 'String' has no call signatures. ==== tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.ts (6 errors) ==== @@ -29,8 +31,8 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = 4; var r6 = c.y(); // error ~ -!!! 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. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'Number' has no call signatures. } @@ -56,6 +58,6 @@ tests/cases/conformance/classes/members/classTypes/instancePropertyInClassType.t r.y = ''; var r6 = c.y(); // error ~ -!!! 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. +!!! message TS6234: This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'? +!!! message TS6234: Type 'String' has no call signatures. } \ No newline at end of file