Repository navigation
fix(parser): propagate deep errors past function-call argument lists - #366
Conversation
When an argument sub-parse failed with a non-:unexpected_token error (e.g. a bare-expression statement deep inside a `function` argument), parse_expr_list_acc/2 treated it as a clean list terminator because error_position/1 only understood :unexpected_token. The list "recovered" and expect_closing emitted a misleading "Expected rparen, got function" pinned at the enclosing call's opener line instead of the real error. Teach error_position/1 to read the position out of :bare_expression, :invalid_assign_target, and :unclosed_delimiter errors so committed?/2 classifies them correctly and the genuine deep error propagates.
…mitted Stabilization follow-up from adversarial review of the deep-error-position fix. Three refinements: - :bare_expression and :invalid_assign_target are now classified as always-committed in committed?/2 rather than position-based. They are statement-level errors only reachable through a function-literal body, so they always represent consumed input. This closes a nil-position fall-through: an Expr.Call/Expr.Paren assignment target (built with meta: nil) yielded a nil position, so the old position-based check still swallowed the deep error and blamed the enclosing call opener. - validate_assign_targets/2 falls back to the `=` operator position when the offending target node carries no position, so the propagated error points at the right line instead of degrading to nil. - error_position/1 keeps the :unclosed_delimiter clause (position-based via the opener) so a delimiter that begins an argument still recovers at the outer boundary. Adds regression rows locking the invalid-assign and non-first-argument unclosed-delimiter paths, which were previously untested.
Stabilization cycle (ultracode review)Ran a multi-agent review (4 dimensions: regression-risk, edge-cases, completeness, test-coverage) with adversarial verification (each finding refuted by 2 independent skeptics) plus a validation gate. 11 findings, 7 confirmed. Results actioned in 5e73e77: Blocker — formatting. The new test tuple wasn't High — nil-position fall-through (real bug, same class as the original). The original outer("ok", function()
f() = 1 -- blamed the `function` keyword on line 1, not here
end)Fix: classify Medium — Not actioned (intentional):
Validation after changes: |
…t argument
An unclosed (/{/[ that begins a non-first call argument was reported as a
misleading "Expected )" at the outer call boundary, while the same
delimiter as the first argument or opened mid-element was correctly blamed
at its opener. The begins-a-non-first-argument case fell through because its
open_pos equals the sub-parse start offset, so committed?/2's strict
position test (error_offset > start_offset) read it as "not committed" and
the list recovered.
Make :unclosed_delimiter unconditionally committed, joining :unexpected_end,
:bare_expression, and :invalid_assign_target. An opened-but-unclosed
delimiter has by construction consumed an opener and content, so it can
never be a clean list terminator and must always propagate as the genuine
deep error. The position-gated path is left for :unexpected_token, which
still relies on it for clean trailing-comma/stray-closer recovery.
|
Folded the deferred follow-up into this PR (65a7c04).
Result — an unclosed delimiter beginning a non-first argument is now blamed at its own opener, consistent with the first-arg and mid-element cases:
Two regression rows added to |
Problem
A parse error deep inside a function-call argument was reported at the opening line of the call, not where the mistake actually is. Given:
the parser emitted
Expected :delimiter::rparen, got :keyword::functionpinned at line 1 (thew:step(opener) instead of line 3.Root cause
In
parse_expr_list_acc/2, when an argument sub-parse fails,committed?/2decides whether the failure is a real deep error to propagate or a clean signal that the argument list ended. Its fallback clause derives "committed" by comparing the error's byte offset against the start token viaerror_position/1, which only understands:unexpected_tokenerrors:The actual failure is a
{:bare_expression, …}error (device.doesntExistis a bare table access, not a valid statement). That shape returnednil, so thecommitted?fallback reported "not committed", the list "recovered" as if the arguments ended just beforefunction, andexpect_closingproduced the misleading "Expected rparen" at the opener. This is exactly the failure mode the comment atparse_expr_list_acc/2warns about — it just never covered non-:unexpected_tokenshapes.Fix
Special-case the position-independent error shapes in
committed?/2so they are always committed, rather than position-gating them througherror_position/1:These shapes can never represent a clean list terminator:
:bare_expression/:invalid_assign_targetare statement-level errors only reachable through afunction() … endbody — i.e. only after a full prefix expression has been consumed.:unclosed_delimiterhas by construction consumed an opener and its content. Gating it on position would make blame depend on whether the opener happens to be the argument's first token versus opened mid-element; always committing it blames the inner opener uniformly.Committing them unconditionally also sidesteps the missing-position problem: an invalid-assign target on a
meta: nilpostfix node (e.g. anExpr.CallLHS) has notarget_position/1. To keepconvert_error/2pointing at the right line,validate_assign_targets/2now takes the=operator position and uses it as a fallback:committed?/2now classifies these as committed and the genuine deep error propagates. The example above now reports:This is the inverse companion to #365 ("blame the opener"): don't let a shallow opener-blame swallow a genuine deep error.
Tests
@deep_propagation_errorstable intest/lua/parser/error_position_test.exs, covering each newly-committed shape (bare expression, invalid assign target with a position-lessExpr.Callnode, and unclosed delimiters both mid-element and beginning a non-first argument).mix test→ 2475 passed, 7 skipped.