fix chained nil-coalesce mis-parse on arity-aware calls#233
Merged
Conversation
The post-arg break in parse_call_or_atom allowed ?? through when looks_like_prefix_binary matched, since ?? is included in the prefix-binary scanner. With a 2+ atom tail (??ident ident ...) the scanner happily treated the chain as a prefix nil-coalesce, and the first call kept absorbing it as another argument. Chained 'mget m "a" ?? mget m "b" ?? 99' then failed verification with ILO-T006 arity mismatch. Once at least one argument has been collected, ?? is unambiguously the infix nil-coalesce on the call result. The first-token case is left alone so 'g ??c 7' still passes a prefix-?? sub-expression as g's arg.
Extends regression_mget_default with chained 'mget m k1 ?? mget m k2 ?? d' across the first-hit, second-hit, both-miss, and no-default shapes, plus an 'at'-based pair to confirm the fix isn't mget-specific. Also drops the stale comment noting the chained form didn't parse. examples/chained-nilcoalesce.ilo demonstrates the now-correct behaviour for in-context learning and acts as a higher-level regression via tests/examples_engines.rs.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
Chained
mget m "a" ?? mget m "b" ?? 99failed at the verifier withILO-T006 arity mismatch: 'mget' expects 2 args, got 3. Singlemget m k ?? dwas fine; only chains broke.Root cause is in
parse_call_or_atom's post-arg break. After each collected argument, the loop checks for an infix operator to stop on, but allows the prefix-binary lookahead (looks_like_prefix_binary) to override that break.??is registered as a prefix-binary candidate (sog ??c 7can pass a prefix-??sub-expression tog), and?? mget m "b"has 3 tail atoms which the scanner happily reads as a prefix nil-coalesce. So the firstmgetkept absorbing?? mget mas its third arg, then"b" ?? 99as its fourth, producing the bogus 3-arg verifier error.Fix: once at least one argument has been collected for a call,
??is unambiguously the infix nil-coalesce on the call result. Don't let the prefix-binary scanner pull it back into call-arg territory. The first-token case is left alone so prefix??c 7in a call-arg position still works.Repro
Before:
After:
What's in the diff
src/parser/mod.rs: in the post-arg infix check inparse_call_or_atom, treatToken::NilCoalesceas always-infix. One condition, one comment block explaining why.tests/regression_mget_default.rs: extend the existing cross-engine harness with chainedmget m k1 ?? mget m k2 ?? din first-hit, second-hit, both-miss and no-default shapes. Add anat-based pair to confirm the fix isn'tmget-specific. Drop the stale comment that said chained??didn't parse.examples/chained-nilcoalesce.ilo: in-context learning example exercised across every engine bytests/examples_engines.rs.Test plan
--run-tree,--run-vm,--run-cranelift.regression_prefix_nil_coalesce(coversg ??c 7) still passes — prefix-??in call-arg position is unaffected.regression_mget_defaultsingle-mgetcases still pass.examples/chained-nilcoalesce.iloruns clean under the examples harness.cargo test --release --features cranelift.cargo fmt --check,cargo clippy --all-targets --release --features craneliftclean.Follow-ups
None. The post-arg infix check was the only place this leaked.