diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-08-24 17:36:47 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-08-24 17:36:47 -0300 |
| commit | 997f11f54322883c3181225f29d101a597f31730 (patch) | |
| tree | 22628b0ca4632fea24e279bc8ea1cc103a15bcb5 /testes | |
| parent | 02060b7a37d88d4e92cf64a008c0651eae432c12 (diff) | |
| download | lua-997f11f54322883c3181225f29d101a597f31730.tar.gz lua-997f11f54322883c3181225f29d101a597f31730.tar.bz2 lua-997f11f54322883c3181225f29d101a597f31730.zip | |
Bug: 'break' may not properly close variable in a 'for' loop
Function 'leaveblock' was generating "break" label before removing
variables from the closing block. If 'createlabel' created a 'close'
instruction (which it did when matching a goto/break that exited
the scope of an upvalue), that instruction would use the wrong level.
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/locals.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/testes/locals.lua b/testes/locals.lua index ddb75054..d50beaa5 100644 --- a/testes/locals.lua +++ b/testes/locals.lua | |||
| @@ -360,6 +360,26 @@ do | |||
| 360 | end | 360 | end |
| 361 | 361 | ||
| 362 | 362 | ||
| 363 | do | ||
| 364 | -- bug in 5.4.4: 'break' may generate wrong 'close' instruction when | ||
| 365 | -- leaving a loop block. | ||
| 366 | |||
| 367 | local closed = false | ||
| 368 | |||
| 369 | local o1 = setmetatable({}, {__close=function() closed = true end}) | ||
| 370 | |||
| 371 | local function test() | ||
| 372 | for k, v in next, {}, nil, o1 do | ||
| 373 | local function f() return k end -- create an upvalue | ||
| 374 | break | ||
| 375 | end | ||
| 376 | assert(closed) | ||
| 377 | end | ||
| 378 | |||
| 379 | test() | ||
| 380 | end | ||
| 381 | |||
| 382 | |||
| 363 | do print("testing errors in __close") | 383 | do print("testing errors in __close") |
| 364 | 384 | ||
| 365 | -- original error is in __close | 385 | -- original error is in __close |
