lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 8b752ddf14c1987411906d07a8c68f72f168b9b7
parent 1bf4b80f1ace8384eb9dd6f7f8b67256b3944a7a
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Sat, 17 Aug 2024 12:36:37 -0300

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.

Diffstat:
Mlcode.c | 3++-
Mtestes/closure.lua | 8++++++++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lcode.c b/lcode.c @@ -31,6 +31,7 @@ #include "lvm.h" +/* (note that expressions VJMP also have jumps.) */ #define hasjumps(e) ((e)->t != (e)->f) @@ -991,7 +992,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); diff --git a/testes/closure.lua b/testes/closure.lua @@ -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 = {}