Skip to content

Aozgaa/abstract accessor impl #12565

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

Merged
merged 2 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -21239,6 +21239,9 @@ namespace ts {
else if (accessor.body === undefined && !(getModifierFlags(accessor) & ModifierFlags.Abstract)) {
return grammarErrorAtPos(getSourceFileOfNode(accessor), accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
}
else if (accessor.body && getModifierFlags(accessor) & ModifierFlags.Abstract) {
return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
}
else if (accessor.typeParameters) {
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_have_type_parameters);
}
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,10 @@
"category": "Error",
"code": 1317
},
"An abstract accessor cannot have an implementation.": {
"category": "Error",
"code": 1318
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down
17 changes: 17 additions & 0 deletions tests/baselines/reference/classAbstractAccessor.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(4,17): error TS1318: An abstract accessor cannot have an implementation.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts(6,17): error TS1318: An abstract accessor cannot have an implementation.


==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractAccessor.ts (2 errors) ====

abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
~~
!!! error TS1318: An abstract accessor cannot have an implementation.
abstract set b(x: string);
abstract set bb(x: string) {} // error
~~
!!! error TS1318: An abstract accessor cannot have an implementation.
}

28 changes: 28 additions & 0 deletions tests/baselines/reference/classAbstractAccessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [classAbstractAccessor.ts]

abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
abstract set b(x: string);
abstract set bb(x: string) {} // error
}


//// [classAbstractAccessor.js]
var A = (function () {
function A() {
}
Object.defineProperty(A.prototype, "aa", {
get: function () { return 1; } // error
,
enumerable: true,
configurable: true
});
Object.defineProperty(A.prototype, "bb", {
set: function (x) { } // error
,
enumerable: true,
configurable: true
});
return A;
}());
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: es5

abstract class A {
abstract get a();
abstract get aa() { return 1; } // error
abstract set b(x: string);
abstract set bb(x: string) {} // error
}