Skip to content

Commit

Permalink
Fix wrong code gen. for indices with comparisons
Browse files Browse the repository at this point in the history
Co-Authored-By: Roberto Ierusalimschy <[email protected]>
  • Loading branch information
2 people authored and well-in-that-case committed Sep 6, 2024
1 parent 1125308 commit b3b61c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define MAXREGS 255


/* (note that expressions VJMP also have jumps.) */
#define hasjumps(e) ((e)->t != (e)->f)


Expand Down Expand Up @@ -1001,7 +1002,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
** or it is a constant.
*/
void luaK_exp2val (FuncState *fs, expdesc *e) {
if (hasjumps(e))
if (e->k == VJMP || hasjumps(e))
luaK_exp2anyreg(fs, e);
else
luaK_dischargevars(fs, e);
Expand Down
8 changes: 8 additions & 0 deletions testes/closure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

print "testing closures"

do -- bug in 5.4.7
_ENV[true] = 10
local function aux () return _ENV[1 < 2] end
assert(aux() == 10)
_ENV[true] = nil
end


local A,B = 0,{g=10}
local function f(x)
local a = {}
Expand Down

0 comments on commit b3b61c0

Please sign in to comment.