Commit c9e560b
## 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>
1 parent 4be7036 commit c9e560b
2 files changed
Lines changed: 43 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
531 | | - | |
532 | | - | |
| 531 | + | |
| 532 | + | |
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
746 | 787 | | |
747 | 788 | | |
0 commit comments