Skip to content

Commit

Permalink
Berry fix walrus bug when assigning to self (#21015)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored Mar 22, 2024
1 parent a34f549 commit c954838
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ All notable changes to this project will be documented in this file.
- LVGL library from v9.0.0 to v9.1.0

### Fixed

- Berry fix walrus bug when assigning to self

### Removed

Expand Down
14 changes: 3 additions & 11 deletions lib/libesp32/berry/src/be_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,23 +728,15 @@ int be_code_setvar(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2, bbool keep_reg)
setsupvar(finfo, OP_SETUPV, e1, src);
break;
case ETMEMBER: /* store to member R(A).RK(B) <- RK(C) */
setsfxvar(finfo, OP_SETMBR, e1, src);
if (keep_reg && e2->type == ETREG) {
case ETINDEX: /* store to member R(A)[RK(B)] <- RK(C) */
setsfxvar(finfo, (e1->type == ETMEMBER) ? OP_SETMBR : OP_SETIDX, e1, src);
if (keep_reg && e2->type == ETREG && e1->v.ss.obj >= be_list_count(finfo->local)) {
/* special case of walrus assignemnt when we need to recreate an ETREG */
code_move(finfo, e1->v.ss.obj, src); /* move from ETREG to MEMBER instance*/
free_expreg(finfo, e2); /* free source (checks only ETREG) */
e2->v.idx = e1->v.ss.obj; /* update to new register */
}
break;
case ETINDEX: /* store to member R(A)[RK(B)] <- RK(C) */
setsfxvar(finfo, OP_SETIDX, e1, src);
if (keep_reg && e2->type == ETREG) {
/* special case of walrus assignemnt when we need to recreate an ETREG */
code_move(finfo, e1->v.ss.obj, src);
free_expreg(finfo, e2); /* free source (checks only ETREG) */
e2->v.idx = e1->v.ss.obj;
}
break;
default:
return 1;
}
Expand Down
14 changes: 14 additions & 0 deletions lib/libesp32/berry/tests/walrus.be
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ import global
def f() return id(global.l[0] := 42) end
assert(f() == 42)
# bug: returns [42, 11]

# bug when using member for self
class confused_walrus
var b
def f()
var c = 1
if self.b := true
c = 2
end
return self
end
end
var ins = confused_walrus()
assert(ins.f() == ins)

0 comments on commit c954838

Please sign in to comment.