diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-07-23 13:58:30 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-07-23 13:58:30 -0300 |
| commit | 7579fc9d7ed90240487251dfb69168f8e64e9294 (patch) | |
| tree | dbf17260333869dc4963c7b3c3dae98d7370e771 /testes/locals.lua | |
| parent | d5bbe955840c5c83e37ed19df4d392d7ba0970ed (diff) | |
| download | lua-7579fc9d7ed90240487251dfb69168f8e64e9294.tar.gz lua-7579fc9d7ed90240487251dfb69168f8e64e9294.tar.bz2 lua-7579fc9d7ed90240487251dfb69168f8e64e9294.zip | |
A close instruction is still inside the scope of the variables it is
closing. The extra close in a repeat-until (to close variables before
repeating the loop) was being coded outside that scope.
Diffstat (limited to 'testes/locals.lua')
| -rw-r--r-- | testes/locals.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/testes/locals.lua b/testes/locals.lua index 6cd10547..e9718341 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
| @@ -1179,6 +1179,25 @@ if rawget(_G, "T") then | |||
| 1179 | end | 1179 | end |
| 1180 | 1180 | ||
| 1181 | 1181 | ||
| 1182 | do | ||
| 1183 | -- detail in scopes of variables in the loop of 'repeat-until' | ||
| 1184 | local res = {} | ||
| 1185 | local function foo (a) | ||
| 1186 | repeat | ||
| 1187 | local x | ||
| 1188 | local i <close> = setmetatable({}, {__close = function () | ||
| 1189 | res[#res + 1] = debug.getlocal(2, 2) -- get 'x' | ||
| 1190 | res[#res + 1] = debug.getlocal(2, 3) -- get 'i' | ||
| 1191 | a = true | ||
| 1192 | end}) | ||
| 1193 | until a | ||
| 1194 | end | ||
| 1195 | foo(false) | ||
| 1196 | -- loop variables still in scope when closing 'i', both when 'repeat' | ||
| 1197 | -- repeats and when 'repeat' stops. | ||
| 1198 | assert(res[1] == "x" and res[2] == "i" and res[3] == "x" and res[4] == "i") | ||
| 1199 | end | ||
| 1200 | |||
| 1182 | 1201 | ||
| 1183 | -- to-be-closed variables in generic for loops | 1202 | -- to-be-closed variables in generic for loops |
| 1184 | do | 1203 | do |
