Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce keyword order of abstract and override #43829

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40782,6 +40782,9 @@ namespace ts {
if (flags & ModifierFlags.Async && lastAsync) {
return grammarErrorOnNode(lastAsync, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "async", "abstract");
}
if (flags & ModifierFlags.Override) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "abstract", "override");
}
}
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.PrivateIdentifier) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_a_private_identifier, "abstract");
Expand Down
15 changes: 12 additions & 3 deletions tests/cases/conformance/override/overrideKeywordOrder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @noTypesAndSymbols: true
// @noEmit: true

class Base {
abstract class Base {
static s1() {}
static s2() {}
m1() {}
m2() {}
abstract m1(): void;
abstract m2(): void;
p1: any;
p2: any;
}
Expand All @@ -17,6 +17,8 @@ class Test1 extends Base {
class Test2 extends Base {
override static s1() {} // error
static override s2() {}
m1() {}
m2() {}
}
class Test3 extends Base {
override public m1() {} // error
Expand All @@ -25,4 +27,11 @@ class Test3 extends Base {
class Test4 extends Base {
override readonly p1: any;
readonly override p2: any; // error
m1() {}
m2() {}
}

abstract class Test5 extends Base {
override abstract m1(): void; // error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you miss update to the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

abstract override m2(): void;
}