diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-02-15 12:28:46 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-02-15 12:28:46 -0300 |
commit | 1f3c6f4534c6411313361697d98d1145a1f030fa (patch) | |
tree | 4fe12910861bced95a9349e6aedb03097837939c | |
parent | 25b143dd34fb587d1e35290c4b25bc08954800e2 (diff) | |
download | lua-github-1f3c6f4534c6411313361697d98d1145a1f030fa.tar.gz |
Bug: Lua can generate wrong code when _ENV is <const>
-rw-r--r-- | lparser.c | 1 | ||||
-rw-r--r-- | testes/attrib.lua | 10 |
2 files changed, 11 insertions, 0 deletions
@@ -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] */ } diff --git a/testes/attrib.lua b/testes/attrib.lua index b1076c76..83821c06 100644 --- a/testes/attrib.lua +++ b/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 |