Skip to content

Commit c1309a6

Browse files
committed
Report TS2516 for non-consecutive abstract method declarations
1 parent 529e444 commit c1309a6

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎tsc/internal/checker/checker.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3639,7 +3639,8 @@ func (c *Checker) checkFunctionOrConstructorSymbolWorker(symbol *ast.Symbol) {
36393639
}
36403640
return
36413641
}
3642-
if ast.NodeIsPresent(subsequentNode.Body()) {
3642+
// Abstract methods can't have an implementation in the same class, so the next method can't be a misnamed one.
3643+
if ast.NodeIsPresent(subsequentNode.Body()) && !ast.HasSyntacticModifier(node, ast.ModifierFlagsAbstract) {
36433644
c.error(errorNode, diagnostics.Function_implementation_name_must_be_0, scanner.DeclarationNameToString(name))
36443645
return
36453646
}

‎tsc/testdata/baselines/reference/compiler/abstractMethodNonConsecutiveDeclarations.errors.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
abstractMethodNonConsecutiveDeclarations.ts(6,5): error TS2389: Function implementation name must be 'func1'.
1+
abstractMethodNonConsecutiveDeclarations.ts(4,14): error TS2516: All declarations of an abstract method must be consecutive.
22
abstractMethodNonConsecutiveDeclarations.ts(14,14): error TS2516: All declarations of an abstract method must be consecutive.
33

44

@@ -7,10 +7,10 @@ abstractMethodNonConsecutiveDeclarations.ts(14,14): error TS2516: All declaratio
77

88
abstract class SeparatedByMethod {
99
abstract func1(): void;
10+
~~~~~
11+
!!! error TS2516: All declarations of an abstract method must be consecutive.
1012

1113
func2(): string {
12-
~~~~~
13-
!!! error TS2389: Function implementation name must be 'func1'.
1414
return 'hi';
1515
}
1616

0 commit comments

Comments
 (0)