aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-14 15:46:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-10-14 15:46:58 -0300
commit52c86797608f1bf927be5bab1e9b97b7d35bdf2c (patch)
tree41165b997293675eeb2a40bffe8417939e76c95e /testes
parent849b2ecbd28793408d21ebd734525ab56ae5ca1e (diff)
downloadlua-52c86797608f1bf927be5bab1e9b97b7d35bdf2c.tar.gz
lua-52c86797608f1bf927be5bab1e9b97b7d35bdf2c.tar.bz2
lua-52c86797608f1bf927be5bab1e9b97b7d35bdf2c.zip
Fixed bug of keys removed from tables vs 'next'
Fixed the bug that a key removed from a table might not be found again by 'next'. (This is needed to allow keys to be removed during a traversal.) This bug was introduced in commit 73ec04fc.
Diffstat (limited to 'testes')
-rw-r--r--testes/nextvar.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index a16d557b..29cb05d5 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -359,6 +359,38 @@ end
359assert(n == 5) 359assert(n == 5)
360 360
361 361
362do
363 print("testing next x GC of deleted keys")
364 -- bug in 5.4.1
365 local co = coroutine.wrap(function (t)
366 for k, v in pairs(t) do
367 local k1 = next(t) -- all previous keys were deleted
368 assert(k == k1) -- current key is the first in the table
369 t[k] = nil
370 local expected = (type(k) == "table" and k[1] or
371 type(k) == "function" and k() or
372 string.sub(k, 1, 1))
373 assert(expected == v)
374 coroutine.yield(v)
375 end
376 end)
377 local t = {}
378 t[{1}] = 1 -- add several unanchored, collectable keys
379 t[{2}] = 2
380 t[string.rep("a", 50)] = "a" -- long string
381 t[string.rep("b", 50)] = "b"
382 t[{3}] = 3
383 t[string.rep("c", 10)] = "c" -- short string
384 t[function () return 10 end] = 10
385 local count = 7
386 while co(t) do
387 collectgarbage("collect") -- collect dead keys
388 count = count - 1
389 end
390 assert(count == 0 and next(t) == nil) -- traversed the whole table
391end
392
393
362local function test (a) 394local function test (a)
363 assert(not pcall(table.insert, a, 2, 20)); 395 assert(not pcall(table.insert, a, 2, 20));
364 table.insert(a, 10); table.insert(a, 2, 20); 396 table.insert(a, 10); table.insert(a, 2, 20);