浏览代码

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.
Roberto Ierusalimschy 11 月之前
父节点
当前提交
782ef85b22
共有 2 个文件被更改,包括 10 次插入1 次删除
  1. 2 1
      lcode.c
  2. 8 0
      testes/closure.lua

+ 2 - 1
lcode.c

@@ -35,6 +35,7 @@
 #define MAXREGS		255
 
 
+/* (note that expressions VJMP also have jumps.) */
 #define hasjumps(e)	((e)->t != (e)->f)
 
 
@@ -985,7 +986,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);

+ 8 - 0
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 = {}