fix(parser): adjust parenthesised call/vararg to a single value#278
Merged
Conversation
Per Lua 5.3 §3.4, `(f())` and `(...)` must adjust to exactly one result. Today the parser strips parens at parse time so multi-value contexts (last RHS, last arg, `return`, last table field) expand every result. Introduce `Expr.Paren` wrapping only `Call`, `MethodCall`, and `Vararg` inners — codegen's call-detection sites all match the bare structs, so the wrapper opts out of expansion. Closes #254 Plan: A42
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.
Adjust parenthesised call/vararg to a single value (Lua 5.3 §3.4)
Plan:
.agents/plans/A42-paren-adjust-single-value.mdCloses #254
Goal
Per Lua 5.3 §3.4,
(f())and(...)must adjust to exactly onevalue. Before this change the parser dropped parens at parse time, so
(f())andf()produced identical ASTs; in multi-value positions(last RHS, last arg,
return, last table field) both expanded to allresults.
Spec repro now produces the expected result:
Success criteria
test/lua/vm/paren_adjust_test.exspins all fourmulti-value positions (last RHS of multi-assign, last
returnvalue,last call argument, last table-constructor field) for both
CallandVararginners. (10 tests, all passing.)constructs.luanow runs end-to-end through line 224. Its skipnarrows from
:allto225..313with a new, accurate reasoncovering the remaining
debug.getinfo/os.time/load-drivenblockers.
calls.lualine 207..208 §3.4 skip entry removed; the file stillpasses with the four remaining unrelated skips.
mix test: 2008 → 2019 passed (+10 paren tests, +1 fromconstructs.lua leaving
:all), 24 → 23 skipped.mix test --only lua53: 12 → 13 files passing.Changes
Mechanism:
Expr.Paren{inner, meta}AST node wraps onlyExpr.Call,Expr.MethodCall, andExpr.Vararg. Other parenthesisedexpressions stay unwrapped — semantically transparent and no need
to disturb the existing AST shape.
parse_paren_expr/1; everything else falls through.multi-value detection sites (
Statement.Return,Statement.Assign,Statement.Local,Expr.Callargs,Expr.MethodCallargs,Expr.Tablelast field) all pattern-match the bare struct, so theParenwrapper naturally opts out of expansion.Paren(one clause each) tokeep AST traversal and round-tripping honest.
Discoveries
constructs.luaadvanced to a differentfailure at line 226:
assert(debug.getinfo(1, "n").name == 'F').debug.getinfo's"n"field isn't wired up for thecurrently-executing closure. Past 226 the file also hits
os.time(line 237, not implemented) and theload()-drivenshort-circuit harness (lines 287–298). These are separate concerns;
the new skip range covers 225..313 with a triage note rather than
expanding this PR's scope.
Expr.Call/Expr.MethodCall/Expr.Varargstructurally, so a singlegen_expr(%Expr.Paren{inner: inner}, ctx) -> gen_expr(inner, ctx)passthrough is enough — no per-site changes needed.
Verification
Out of scope (intentional)
constructs.luafailures past line 225 (covered by thenew narrowed skip; future plans should triage individually).