From 9386e49a3173b68e8b5a7ba882c4c2faf557b61e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 16 Jun 2025 16:29:32 -0300 Subject: New metatable in an all-weak table can fool the GC All-weak tables are not being revisited after being visited during propagation; if it gets a new metatable after that, the new metatable may not be marked. --- testes/gc.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'testes/gc.lua') diff --git a/testes/gc.lua b/testes/gc.lua index 5d2b3085..62713dac 100644 --- a/testes/gc.lua +++ b/testes/gc.lua @@ -294,6 +294,16 @@ do -- invalid mode end +if T then -- bug since 5.3: all-weak tables are not being revisited + T.gcstate("propagate") + local t = setmetatable({}, {__mode = "kv"}) + T.gcstate("enteratomic") -- 't' was visited + setmetatable(t, {__mode = "kv"}) + T.gcstate("pause") -- its new metatable is not being visited + assert(getmetatable(t).__mode == "kv") +end + + -- 'bug' in 5.1 a = {} local t = {x = 10} -- cgit v1.2.3-55-g6feb