Skip to content

Commit

Permalink
Merge pull request #454 from s-hadinger/walrus_fix_member
Browse files Browse the repository at this point in the history
Fix walrus assignment with member
  • Loading branch information
skiars authored Dec 23, 2024
2 parents 9a7c4b5 + 681eb23 commit 23c6576
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/be_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ int be_code_setvar(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2, bbool keep_reg)
free_expreg(finfo, e2); /* free source (checks only ETREG) */
*e2 = *e1; /* now e2 is e1 ETLOCAL */
}
} else {
*e2 = *e1; /* ETLOCAL wins over ETREG */
}
break;
case ETGLOBAL: /* store to grobal R(A) -> G(Bx) by global index */
Expand Down
16 changes: 16 additions & 0 deletions tests/walrus.be
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ def check_overwrite_builtin()
end

check_overwrite_builtin()

# Bug when dereferencing in a walrus
class Test_walrus_member
var a
def init()
self.a = 2
end
def f()
var v
if (v := self.a) != nil # here is where the bug happens
return v # 'v' would have a wrong value
end
end
end
var t = Test_walrus_member()
assert(t.f() == 2)

0 comments on commit 23c6576

Please sign in to comment.