Don't let an impermissible literal shadow an overlapping argument node#163
Open
WouterGritter wants to merge 1 commit into
Open
Don't let an impermissible literal shadow an overlapping argument node#163WouterGritter wants to merge 1 commit into
WouterGritter wants to merge 1 commit into
Conversation
`CommandNode#getRelevantNodes` short-circuits to a literal whose name matches the next token regardless of whether the source can use it. `parseNodes` then skips that literal via canUse and, because the relevant-node set was the literal alone, never falls back to the argument siblings, making an argument node whose text overlaps the literal unreachable for any source lacking the literal's permission. Add a source-aware `getRelevantNodes(StringReader, source)` overload that only short-circuits to the matched literal when the source can use it, otherwise falling back to the argument nodes. The permitted case is byte-for-byte unchanged (still returns the single literal), so literal priority is preserved.
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.
CommandNode#getRelevantNodesshort-circuits to a literal as soon as its name matches the next token, without considering whether the source can use it:parseNodesthen filters that node out with canUse(source) and moves on:Because the relevant-node set was the matched literal alone, there is nothing to fall back to; the argument siblings are never tried. So if a literal (e.g. bar, gated behind
requires(...)) sits next to an argument node whose text overlaps it (e.g. ), a source that can't use bar can't reach either, even though the argument would happily accept the input. A permission-gated literal silently makes an overlapping argument unreachable.Fix
Add a source-aware
getRelevantNodes(StringReader, S source)overload that only short-circuits to the matched literal when the source can actually use it; otherwise it falls back to the argument nodes.parseNodesnow calls this overload.The crucial property: when the literal is usable, the result is identical to before (
singleton(literal)), so literal priority and the short-circuit are fully preserved. The fallback only kicks in for the shadowing case. This avoids the regression that "always return literal + arguments" would cause, where e.g. a greedy-string sibling could start beating a previously-prioritised literal in the potentials sort.