Skip to content

Commit 60c7340

Browse files
authored
Merge pull request #12565 from Microsoft/aozgaa/abstractAccessorImpl
Aozgaa/abstract accessor impl
2 parents 1418fd1 + 4b0697f commit 60c7340

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(4,17): error TS1318: An abstract accessor cannot have an implementation.
2+
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(6,17): error TS1318: An abstract accessor cannot have an implementation.
3+
4+
5+
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (2 errors) ====
6+
7+
abstract class A {
8+
abstract get a();
9+
abstract get aa() { return 1; } // error
10+
~~
11+
!!! error TS1318: An abstract accessor cannot have an implementation.
12+
abstract set b(x: string);
13+
abstract set bb(x: string) {} // error
14+
~~
15+
!!! error TS1318: An abstract accessor cannot have an implementation.
16+
}
17+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [classAbstractAccessor.ts]
2+
3+
abstract class A {
4+
abstract get a();
5+
abstract get aa() { return 1; } // error
6+
abstract set b(x: string);
7+
abstract set bb(x: string) {} // error
8+
}
9+
10+
11+
//// [classAbstractAccessor.js]
12+
var A = (function () {
13+
function A() {
14+
}
15+
Object.defineProperty(A.prototype, "aa", {
16+
get: function () { return 1; } // error
17+
,
18+
enumerable: true,
19+
configurable: true
20+
});
21+
Object.defineProperty(A.prototype, "bb", {
22+
set: function (x) { } // error
23+
,
24+
enumerable: true,
25+
configurable: true
26+
});
27+
return A;
28+
}());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es5
2+
3+
abstract class A {
4+
abstract get a();
5+
abstract get aa() { return 1; } // error
6+
abstract set b(x: string);
7+
abstract set bb(x: string) {} // error
8+
}

0 commit comments

Comments
 (0)