diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-10-30 10:39:55 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-10-30 10:39:55 -0300 |
| commit | 0149b781d438091ce086449101a916e9b4456b4e (patch) | |
| tree | c57e788c302ecf257614c9c19b48336e54522a2d | |
| parent | d4eff00234dc55dac4cb86b6187f5607c1254f9b (diff) | |
| download | lua-0149b781d438091ce086449101a916e9b4456b4e.tar.gz lua-0149b781d438091ce086449101a916e9b4456b4e.tar.bz2 lua-0149b781d438091ce086449101a916e9b4456b4e.zip | |
Case VVARGIND added to luaK_storevar
In a global initialization, the variable does not pass through
'check_readonly', and therefore a VVARGIND is not normalized to a
VINDEXED.
| -rw-r--r-- | lcode.c | 4 | ||||
| -rw-r--r-- | testes/vararg.lua | 12 |
2 files changed, 16 insertions, 0 deletions
| @@ -1109,6 +1109,10 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { | |||
| 1109 | codeABRK(fs, OP_SETFIELD, var->u.ind.t, var->u.ind.idx, ex); | 1109 | codeABRK(fs, OP_SETFIELD, var->u.ind.t, var->u.ind.idx, ex); |
| 1110 | break; | 1110 | break; |
| 1111 | } | 1111 | } |
| 1112 | case VVARGIND: { | ||
| 1113 | fs->f->flag |= PF_VATAB; /* function will need a vararg table */ | ||
| 1114 | /* now, assignment is to a regular table */ | ||
| 1115 | } /* FALLTHROUGH */ | ||
| 1112 | case VINDEXED: { | 1116 | case VINDEXED: { |
| 1113 | codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex); | 1117 | codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex); |
| 1114 | break; | 1118 | break; |
diff --git a/testes/vararg.lua b/testes/vararg.lua index 5711f78b..840c3eee 100644 --- a/testes/vararg.lua +++ b/testes/vararg.lua | |||
| @@ -184,6 +184,18 @@ do -- _ENV as vararg parameter | |||
| 184 | a = 10 | 184 | a = 10 |
| 185 | end ]] | 185 | end ]] |
| 186 | assert(string.find(msg, "const variable 'a'")) | 186 | assert(string.find(msg, "const variable 'a'")) |
| 187 | |||
| 188 | local function aux (... | _ENV) | ||
| 189 | global a; a = 10 | ||
| 190 | return a | ||
| 191 | end | ||
| 192 | assert(aux() == 10) | ||
| 193 | |||
| 194 | local function aux (... | _ENV) | ||
| 195 | global a = 10 | ||
| 196 | return a | ||
| 197 | end | ||
| 198 | assert(aux() == 10) | ||
| 187 | end | 199 | end |
| 188 | 200 | ||
| 189 | 201 | ||
