Skip to content

Commit

Permalink
Bug: Lua can generate wrong code when _ENV is <const>
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-ieru committed Feb 15, 2022
1 parent 25b143d commit 1f3c6f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] */
}
Expand Down
10 changes: 10 additions & 0 deletions testes/attrib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1f3c6f4

Please sign in to comment.