Berry fix static allocation when superclass is a member (#20385)

This commit is contained in:
s-hadinger 2024-01-03 16:12:47 +01:00 committed by GitHub
parent 03aea58a4c
commit 6768ebc2ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -1571,15 +1571,11 @@ static void class_stmt(bparser *parser)
begin_block(parser->finfo, &binfo, 0);
bstring *class_str = parser_newstr(parser, "_class"); /* we always define `_class` local variable */
if (e.type == ETLOCAL) {
bexpdesc e1; /* if inline class, we add a second local variable for _class */
init_exp(&e1, ETLOCAL, 0);
e1.v.idx = new_localvar(parser, class_str);
be_code_setvar(parser->finfo, &e1, &e, 1);
} else { /* if global class, we just reuse the newly created class in the register */
init_exp(&e, ETLOCAL, 0);
e.v.idx = new_localvar(parser, class_str);
}
begin_varinfo(parser, class_str);
class_block(parser, c, &e);

View File

@ -155,3 +155,12 @@ assert(A.a == 1)
assert(A.b == A)
assert(A.c == [1, A])
assert(A.f(1) == A)
# bug when superclass is a member
# the following would break with:
#
# attribute_error: class 'B' cannot assign to static attribute 'aa'
# stack traceback:
# stdin:1: in function `main`
class B end m = module('m') m.B = B
class A : m.B static aa = 1 end