Skip to content

Commit

Permalink
Merge pull request #388 from s-hadinger/fix_superclass_member
Browse files Browse the repository at this point in the history
Fix wrong register when superclass is a member
  • Loading branch information
skiars authored Jan 23, 2024
2 parents 97e0fca + 8e64e46 commit 3d8aee8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/be_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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);

begin_varinfo(parser, class_str);

class_block(parser, c, &e);
Expand Down
9 changes: 9 additions & 0 deletions tests/class_static.be
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3d8aee8

Please sign in to comment.