From ce83831c49baa816fd1d8f75692a2364a60b4ff9 Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 19 Aug 2024 13:25:51 +0200 Subject: [PATCH] Fix table.clear not resetting cached length --- src/ltable.cpp | 4 ++++ testes/pluto/basic.pluto | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/ltable.cpp b/src/ltable.cpp index d0c43e21e..1a962e44a 100644 --- a/src/ltable.cpp +++ b/src/ltable.cpp @@ -1035,6 +1035,10 @@ LUAI_FUNC void luaH_clear (lua_State *L, Table *t) { /* clear hash part */ freehash(L, t); setnodevector(L, t, 0); + /* clear cached length */ +#ifndef PLUTO_DISABLE_LENGTH_CACHE + t->length = 0; +#endif } diff --git a/testes/pluto/basic.pluto b/testes/pluto/basic.pluto index 8870c12ff..c236c9033 100644 --- a/testes/pluto/basic.pluto +++ b/testes/pluto/basic.pluto @@ -595,6 +595,11 @@ do rawset(t, i, "Hello") end assert(#t == 1000) + + t = {1} + assert(#t == 1) + t:clear() + assert(#t == 0) end print "Testing null coalescing operator."