浏览代码

Bug: Lua can generate wrong code when _ENV is <const>

Roberto Ierusalimschy 3 年之前
父节点
当前提交
1f3c6f4534
共有 2 个文件被更改,包括 11 次插入0 次删除
  1. 1 0
      lparser.c
  2. 10 0
      testes/attrib.lua

+ 1 - 0
lparser.c

@@ -468,6 +468,7 @@ static void singlevar (LexState *ls, expdesc *var) {
     expdesc key;
     singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */
     lua_assert(var->k != VVOID);  /* this one must exist */
+    luaK_exp2anyregup(fs, var);  /* but could be a constant */
     codestring(&key, varname);  /* key is variable name */
     luaK_indexed(fs, var, &key);  /* env[varname] */
   }

+ 10 - 0
testes/attrib.lua

@@ -434,6 +434,16 @@ a.aVeryLongName012345678901234567890123456789012345678901234567890123456789 ==
 10)
 
 
+do
+  -- _ENV constant
+  local function foo ()
+    local _ENV <const> = 11
+    X = "hi"
+  end
+  local st, msg = pcall(foo)
+  assert(not st and string.find(msg, "number"))
+end
+
 
 -- test of large float/integer indices