diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-08-17 12:37:04 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-08-17 12:37:04 -0300 |
commit | 782ef85b22f89d1cd1ab083202f018668d26e4b0 (patch) | |
tree | 74eb4ee9e4052febe4703c9fce7df4c013cb69b3 | |
parent | 30982bec968fd34694b5be3ecbbc92de78d8eacb (diff) | |
download | lua-782ef85b22f89d1cd1ab083202f018668d26e4b0.tar.gz lua-782ef85b22f89d1cd1ab083202f018668d26e4b0.tar.bz2 lua-782ef85b22f89d1cd1ab083202f018668d26e4b0.zip |
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.
-rw-r--r-- | lcode.c | 3 | ||||
-rw-r--r-- | testes/closure.lua | 8 |
2 files changed, 10 insertions, 1 deletions
@@ -35,6 +35,7 @@ | |||
35 | #define MAXREGS 255 | 35 | #define MAXREGS 255 |
36 | 36 | ||
37 | 37 | ||
38 | /* (note that expressions VJMP also have jumps.) */ | ||
38 | #define hasjumps(e) ((e)->t != (e)->f) | 39 | #define hasjumps(e) ((e)->t != (e)->f) |
39 | 40 | ||
40 | 41 | ||
@@ -985,7 +986,7 @@ void luaK_exp2anyregup (FuncState *fs, expdesc *e) { | |||
985 | ** or it is a constant. | 986 | ** or it is a constant. |
986 | */ | 987 | */ |
987 | void luaK_exp2val (FuncState *fs, expdesc *e) { | 988 | void luaK_exp2val (FuncState *fs, expdesc *e) { |
988 | if (hasjumps(e)) | 989 | if (e->k == VJMP || hasjumps(e)) |
989 | luaK_exp2anyreg(fs, e); | 990 | luaK_exp2anyreg(fs, e); |
990 | else | 991 | else |
991 | luaK_dischargevars(fs, e); | 992 | luaK_dischargevars(fs, e); |
diff --git a/testes/closure.lua b/testes/closure.lua index ea038e82..37271472 100644 --- a/testes/closure.lua +++ b/testes/closure.lua | |||
@@ -3,6 +3,14 @@ | |||
3 | 3 | ||
4 | print "testing closures" | 4 | print "testing closures" |
5 | 5 | ||
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 | |||
6 | local A,B = 0,{g=10} | 14 | local A,B = 0,{g=10} |
7 | local function f(x) | 15 | local function f(x) |
8 | local a = {} | 16 | local a = {} |