Skip to content

Commit 2378c0b

Browse files
authored
fix(53242): Wrong error message when defined abstract property in non-abstract class (#53251)
1 parent e08a2db commit 2378c0b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47002,7 +47002,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4700247002
return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration);
4700347003
}
4700447004
if (!(node.parent.kind === SyntaxKind.ClassDeclaration && hasSyntacticModifier(node.parent, ModifierFlags.Abstract))) {
47005-
return grammarErrorOnNode(modifier, Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class);
47005+
const message = node.kind === SyntaxKind.PropertyDeclaration
47006+
? Diagnostics.Abstract_properties_can_only_appear_within_an_abstract_class
47007+
: Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class;
47008+
return grammarErrorOnNode(modifier, message);
4700647009
}
4700747010
if (flags & ModifierFlags.Static) {
4700847011
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,10 @@
811811
"category": "Error",
812812
"code": 1252
813813
},
814+
"Abstract properties can only appear within an abstract class.": {
815+
"category": "Error",
816+
"code": 1253
817+
},
814818
"A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.": {
815819
"category": "Error",
816820
"code": 1254

tests/baselines/reference/abstractPropertyNegative.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstra
33
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'.
44
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'.
55
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'readonlyProp' from class 'B'.
6-
tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class.
6+
tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1253: Abstract properties can only appear within an abstract class.
77
tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected.
88
tests/cases/compiler/abstractPropertyNegative.ts(19,3): error TS2540: Cannot assign to 'ro' because it is a read-only property.
99
tests/cases/compiler/abstractPropertyNegative.ts(25,5): error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'WrongTypeProperty'.
@@ -45,7 +45,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
4545
readonly ro = "readonly please";
4646
abstract notAllowed: string;
4747
~~~~~~~~
48-
!!! error TS1244: Abstract methods can only appear within an abstract class.
48+
!!! error TS1253: Abstract properties can only appear within an abstract class.
4949
get concreteWithNoBody(): string;
5050
~
5151
!!! error TS1005: '{' expected.

0 commit comments

Comments
 (0)