Skip to content

Commit 782ef85

Browse files
committed
Bug: wrong code gen. for indices with comparisons
In function 'luaK_exp2val', used to generate code for indices: Macro 'hasjumps' does not consider the case when the whole expression is a "jump" (a test). In all other of its uses, the surrounding code ensures that the expression cannot be VJMP.
1 parent 30982be commit 782ef85

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lcode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define MAXREGS 255
3636

3737

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

4041

@@ -985,7 +986,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) {
985986
** or it is a constant.
986987
*/
987988
void luaK_exp2val (FuncState *fs, expdesc *e) {
988-
if (hasjumps(e))
989+
if (e->k == VJMP || hasjumps(e))
989990
luaK_exp2anyreg(fs, e);
990991
else
991992
luaK_dischargevars(fs, e);

testes/closure.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
print "testing closures"
55

6+
do -- bug in 5.4.7
7+
_ENV[true] = 10
8+
local function aux () return _ENV[1 < 2] end
9+
assert(aux() == 10)
10+
_ENV[true] = nil
11+
end
12+
13+
614
local A,B = 0,{g=10}
715
local function f(x)
816
local a = {}

0 commit comments

Comments
 (0)