Skip to content

Commit 3cd1731

Browse files
author
Arthur Ozga
committed
abstract accessors can't have implementations
1 parent 1418fd1 commit 3cd1731

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21239,6 +21239,9 @@ namespace ts {
2123921239
else if (accessor.body === undefined && !(getModifierFlags(accessor) & ModifierFlags.Abstract)) {
2124021240
return grammarErrorAtPos(getSourceFileOfNode(accessor), accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
2124121241
}
21242+
else if (accessor.body && getModifierFlags(accessor) & ModifierFlags.Abstract) {
21243+
return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
21244+
}
2124221245
else if (accessor.typeParameters) {
2124321246
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
2124421247
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,10 @@
851851
"category": "Error",
852852
"code": 1317
853853
},
854+
"An abstract accessor cannot have an implementation.": {
855+
"category": "Error",
856+
"code": 1318
857+
},
854858
"Duplicate identifier '{0}'.": {
855859
"category": "Error",
856860
"code": 2300
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(2,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2+
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(3,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3+
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(4,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
4+
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(5,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
5+
6+
7+
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (4 errors) ====
8+
abstract class A {
9+
abstract get a();
10+
~
11+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
12+
abstract get aa() { return 1; } // error
13+
~~
14+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
15+
abstract set b(x: string);
16+
~
17+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
18+
abstract set bb(x: string) {} // error
19+
~~
20+
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
21+
}
22+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [classAbstractAccessor.ts]
2+
abstract class A {
3+
abstract get a();
4+
abstract get aa() { return 1; } // error
5+
abstract set b(x: string);
6+
abstract set bb(x: string) {} // error
7+
}
8+
9+
10+
//// [classAbstractAccessor.js]
11+
var A = (function () {
12+
function A() {
13+
}
14+
Object.defineProperty(A.prototype, "aa", {
15+
get: function () { return 1; } // error
16+
,
17+
enumerable: true,
18+
configurable: true
19+
});
20+
Object.defineProperty(A.prototype, "bb", {
21+
set: function (x) { } // error
22+
,
23+
enumerable: true,
24+
configurable: true
25+
});
26+
return A;
27+
}());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
abstract class A {
2+
abstract get a();
3+
abstract get aa() { return 1; } // error
4+
abstract set b(x: string);
5+
abstract set bb(x: string) {} // error
6+
}

0 commit comments

Comments
 (0)