Repository navigation
fix(semantic): preserve vararg bindings and result types - #1294
Merged
Merged
Conversation
Vararg uses can be missed by reference collection. Type inference also
confuses whole tuple values with separate result slots. This causes
false diagnostics, missing editor references, and incorrect types.
This use must not produce an unused warning:
local function forward(...)
print(...)
end
forward('hello')
Record each ... use against its function's declaration so reference
queries and unused checks can find it.
Tuple-valued arguments must remain whole when forwarded or packed:
---@PARAM ... [string, integer]
local function pack(...)
local packed = {...}
return packed[2] -- [string, integer]
end
pack({'a', 1}, {'b', 2})
A trailing ... in the annotation instead expands the tuple fields into
separate arguments and results:
---@PARAM ... [string, integer]...
local function forward(...) return ... end
local text, count = forward('a', 1)
VariadicType::Base previously handled both repetition and tuple
expansion. Add a Repeat(LuaType) variant to VariadicType for repeated
whole values. This keeps each tuple table as one value when forwarding
or packing. Keep Base for declared T... expansion, which can wait until
generic types are known, and Multi for known result slots.
lewis6991
force-pushed
the
rewrite-vararg-usage
branch
from
October 15, 2026 08:58
509927e to
0bc11af
Compare
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.
Vararg uses are missing from reference collection after the rewrite. This produces false unused warnings and prevents definition and reference queries from finding
...:Record each use against the nearest function's vararg declaration. A use in an inner function must not mark the outer function's varargs as used.
Type inference also confuses repeated tuple values with separate result slots. These annotations describe different arguments:
VariadicType::Basepreviously represented both repetition and declared tuple expansion. AddRepeat(LuaType)for repeated whole values. KeepBasefor declaredT...expansion, which can wait until generic types are known, andMultifor known result slots.Carry this distinction through forwarding, table packing, generic callbacks, and
select,pcall, andxpcall. Apply Lua's single-value adjustment to parentheses, operators, index keys, and non-final expressions:Keep callback parameter compatibility separate from result value compatibility. An integer result can supply a number result, while incompatible callback parameters and redundant direct-call arguments still produce diagnostics.