Skip to content

Fix positional skipping for grouped conflicts with allow_missing_positional#6378

Draft
jeremy99981 wants to merge 2 commits into
clap-rs:masterfrom
jeremy99981:fix/1794-positional-conflict-skip
Draft

Fix positional skipping for grouped conflicts with allow_missing_positional#6378
jeremy99981 wants to merge 2 commits into
clap-rs:masterfrom
jeremy99981:fix/1794-positional-conflict-skip

Conversation

@jeremy99981
Copy link
Copy Markdown

@jeremy99981 jeremy99981 commented May 13, 2026

This PR fixes #1794.

Problem:
When allow_missing_positional(true) is used with an ArgGroup, values can still be assigned to a positional that conflicts with an already-present option from the same group. In multi-positional cases, this causes an avoidable ArgumentConflict instead of advancing to the next valid positional.

Cause:
Positional skipping logic only considered syntax cues (like whether the next token looked like an option/subcommand), not whether the current positional was already in conflict with arguments that had been parsed.

Solution:

  • Update positional-counter correction in the parser to skip positionals that conflict with already-present args when allow_missing_positional is enabled.
  • Include both explicit arg conflicts and same non-multiple ArgGroup membership conflicts.
  • Re-enable and update issue_1794 parse-behavior test and add a new regression test for multiple conflicting positionals (pos1, pos2, option1) ensuring the value lands on pos3.

Testing:

  • cargo test --test builder issue_1794 -- --nocapture
  • cargo test --test builder groups::
  • cargo test --test builder allow_missing_positional
  • cargo fmt --all --check
  • cargo test --test builder

Notes:
If this issue is still eligible for the IssueHunt bounty, I’m happy to follow the project’s normal bounty redemption process after review and merge.

@epage
Copy link
Copy Markdown
Member

epage commented May 13, 2026

Moving to a draft as #1794 is not marked as being ready for implementation.

@epage epage marked this pull request as draft May 13, 2026 20:04
@jeremy99981 jeremy99981 force-pushed the fix/1794-positional-conflict-skip branch from ded0f67 to 03ffbe1 Compare May 13, 2026 20:09
@jeremy99981
Copy link
Copy Markdown
Author

Thanks for the heads-up, understood. I’ll keep this as draft until #1794 is marked ready for implementation.

@jeremy99981 jeremy99981 marked this pull request as ready for review May 13, 2026 20:19
@jeremy99981 jeremy99981 marked this pull request as draft May 13, 2026 20:19
@pksunkara
Copy link
Copy Markdown
Member

@jeremy99981 Design needs to be agreed upon first in the issue. Can you please add a detailed comment about your design on that issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conflicting with a positional should allow users to skip it, passing in another positional instead

3 participants