Fix: table.update no longer errors when replacing non-table with table (#8694)#8751
Merged
vadi2 merged 2 commits intoMudlet:developmentfrom Jan 23, 2026
Merged
Conversation
Mudlet#8694) When table.update was called with a non-table value (number, string, boolean) at a key where the second table had a table value, it would error with "bad argument #1 to 'pairs' (table expected, got number)". The fix checks if the existing value is actually a table before attempting to recursively merge, otherwise it replaces entirely. Added tests for: - Replacing number with table - Replacing table with non-table - Merging nested tables - Replacing string/boolean with table 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
Contributor
|
#8704 fixes this already, test cases are nice though |
Member
Contributor
Author
Only recurse when both source and destination are tables. Otherwise, just replace the value directly.
vadi2
approved these changes
Jan 23, 2026
vadi2
added a commit
that referenced
this pull request
Feb 3, 2026
#8694) (#8751) ## Summary Fixes #8694 - `table.update` would error when the first table had a non-table value (number, string, boolean) at a key where the second table had a table value. **Example that crashed:** ```lua table.update({ x = 1 }, { x = { y = 2 } }) -- Error: bad argument #1 to 'pairs' (table expected, got number) ``` **Root cause:** The recursion logic `tbl[k] = table.update(tbl[k] or {}, v)` only checked for nil/false before recursing, not for other non-table types. **Fix:** Check `type(existing) == "table"` before passing to recursive call. ## Test plan - [x] Added 5 new test cases in `TableUtils_spec.lua`: - Replace number with table - Replace table with number - Merge nested tables (both tables) - Replace string with table - Replace boolean with table - [x] Verified fix works: `luajit -e "dofile('...TableUtils.lua'); print(table.update({x=1}, {x={y=2}}).x.y)"` outputs `2` ## Notes Tests require running inside Mudlet with `runTests` command (uses Busted framework loaded by Mudlet). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Vadim Peretokin <vperetokin@hey.com> (cherry picked from commit c9e560b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8694 -
table.updatewould error when the first table had a non-table value (number, string, boolean) at a key where the second table had a table value.Example that crashed:
Root cause: The recursion logic
tbl[k] = table.update(tbl[k] or {}, v)only checked for nil/false before recursing, not for other non-table types.Fix: Check
type(existing) == "table"before passing to recursive call.Test plan
Added 5 new test cases in
TableUtils_spec.lua:Verified fix works:
luajit -e "dofile('...TableUtils.lua'); print(table.update({x=1}, {x={y=2}}).x.y)"outputs2Notes
Tests require running inside Mudlet with
runTestscommand (uses Busted framework loaded by Mudlet).🤖 Generated with Claude Code