Skip to content

Conversation

@ThomasWaldmann
Copy link
Contributor

@ThomasWaldmann ThomasWaldmann commented Nov 16, 2025

Fixes #183.

When completing commands with a subparser that uses nargs=REMAINDER, zsh could
emit:

_arguments:comparguments:327: doubled rest argument definition: *::: :->repro

Root cause:

  • The zsh template appended the default positional/rest specs (': :{prefix}_commands' and
    '*::: :->{name}') on every function invocation. It only checked for generic
    variadic/remainder tokens ((*), (-)*) and not whether the exact default entry
    (*::: :->{name}) had already been added. Repeated invocations led to duplicated
    rest specs and the _arguments error above.

Fix:

  • Add a per-function guard variable {prefix}_defaults_added, initialized alongside
    {prefix}_options and set to 1 after the first append. This guarantees that the
    default '*::: :->{name}' is added at most once per session.
  • Keep (and extend) the presence checks: only append the defaults if neither a
    variadic/rest token ((*), (-)*) nor the exact default entry is already present.

Impact:

  • Eliminates duplicated *::: :->… entries and the “doubled rest argument definition”
    error in zsh, including across multiple invocations and after re-sourcing the file.
  • Generated zsh output is unchanged except for the guard variable lines.

@ThomasWaldmann ThomasWaldmann changed the title fix for "doubled rest" zsh: prevent duplicate default REMAINDER spec in generated completions Nov 16, 2025
@ThomasWaldmann
Copy link
Contributor Author

Maybe I could even fix #183 with this, Junie AI was helpful.

I manually tested it, it works. But carefully review, I have no idea what I am doing here.

@ThomasWaldmann
Copy link
Contributor Author

That "thesis" commit comment was also written by Junie, btw. :-)

@casperdcl casperdcl force-pushed the doubled-rest-fix branch 2 times, most recently from 6de320a to 7ac13e3 Compare November 16, 2025 23:42
@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.18%. Comparing base (acc76fd) to head (171be68).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   89.18%   89.18%           
=======================================
  Files           3        3           
  Lines         370      370           
=======================================
  Hits          330      330           
  Misses         40       40           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; wdyt @Freed-Wu @skshetry?

- per-function guard variable `{prefix}_defaults_added`
- only append defaults if `(*)`/`(-)*`/default is missing
@ThomasWaldmann
Copy link
Contributor Author

Oops, I hope I didn't kill anything here by force-pushing.
I rebased this on current main and also adapted the failing test.

@casperdcl
Copy link
Collaborator

casperdcl commented Nov 17, 2025

just force-pushed:

  • human-written commit msg
  • fix tests
  • fix flake8

This comment was marked as spam.

@casperdcl casperdcl merged commit ad3d4ce into iterative:main Nov 17, 2025
7 checks passed
@ThomasWaldmann ThomasWaldmann deleted the doubled-rest-fix branch November 17, 2025 14:23
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.

zsh: doubled rest argument definition: *::: :->b4 seen in b4

2 participants