Skip to content

Commit 8ac51c3

Browse files
author
chrisd08
authored
Fixes class getters inheritance bug (#850)
1 parent abeefbf commit 8ac51c3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/lualib/Descriptors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function ____descriptorNewindex(this: any, key: string, value: any): void {
5050

5151
// It's also used directly in class transform to add descriptors to the prototype
5252
function __TS__SetDescriptor(this: void, metatable: Metatable, prop: string, descriptor: PropertyDescriptor): void {
53-
if (!metatable._descriptors) metatable._descriptors = {};
53+
if (!rawget(metatable, "_descriptors")) metatable._descriptors = {};
5454
metatable._descriptors[prop] = descriptor;
5555

5656
if (descriptor.get) metatable.__index = ____descriptorIndex;

test/unit/classes/accessors.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ test("get accessor override accessor", () => {
6666
`.expectToMatchJsResult();
6767
});
6868

69+
test("get accessor override accessor (multiple)", () => {
70+
util.testFunction`
71+
class Foo {
72+
_foo = "foo";
73+
get foo() { return this._foo; }
74+
}
75+
class Bar extends Foo {
76+
_bar = "bar";
77+
get foo() { return this._bar; }
78+
}
79+
class Baz extends Foo {
80+
_baz = "baz";
81+
get foo() { return this._baz; }
82+
}
83+
const bar = new Bar();
84+
const baz = new Baz();
85+
return bar.foo + baz.foo;
86+
`.expectToMatchJsResult();
87+
});
88+
6989
test("get accessor from interface", () => {
7090
util.testFunction`
7191
class Foo {

0 commit comments

Comments
 (0)