Repository navigation
fix(tablelib): follow Lua 5.4 range rules in table.concat - #89
Merged
Merged
Conversation
table.concat clamped i and j to the table length before concatenating, so
a range with i > j could still return an element (concat(t, ',', 4, 3)
returned t[3]), ranges past the border were silently truncated instead of
raising, and indices below 1 were ignored. A single element was returned
unconverted, so concat({1}) produced a number.
table.concat now walks i..j exactly as lua's tconcat does: an empty range
gives "", every element in the range must be a string or number, and the
result is always a string.
skhaz
approved these changes
Nov 15, 2026
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.
Defect
table.concatclampsiandjto the table length before it concatenates:Cause
tableConcatclampsito[1, #t]andjto#t, so an empty range whoseilies past the border becomes a one-element range, out-of-range elements are skipped instead of reported, and indices below 1 are dropped. It then concatenates through the VM concat helper, which returns a lone operand unconverted.Fix
tableConcatfollowstconcatfrom Lua 5.4: it walksi..jexactly as given, an empty range yields"", every element must be a string or a number (otherwise the existing "invalid value" error is raised with the index), and the result is built as a string.Tests
tablelib_concat_test.gocovers whole and partial ranges,i > jinside and past the border, empty tables, index 0 and negative indices, a single element (string result), and the errors forjpast the border andibelow 1. Expected values come from the Lua 5.4 reference interpreter. 7 cases fail onmain.Verification
go vet ./...,golangci-lintv2.8.0 with the CI flags,go test ./...(full fixture corpus), the coverage collector run, and the race "other" shard (go test -raceon all non-fixture tests and the non-regression fixture categories) pass. The regression-fixture race shards are left to CI.The runtime picks this up through a go-lua dependency bump after merge.