Skip to content

Commit

Permalink
Fix table.clear not resetting cached length
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan authored and well-in-that-case committed Aug 21, 2024
1 parent 83b9139 commit 2335598
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
5 changes: 5 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ do
rawset(t, i, "Hello")
end
assert(#t == 1000)

t = {1}
assert(#t == 1)
table.clear(t)
assert(#t == 0)
end

print "Testing null coalescing operator."
Expand Down

0 comments on commit 2335598

Please sign in to comment.