Commit 9b5435f
committed
zsh: prevent duplicate default REMAINDER spec in generated completions
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.1 parent acc76fd commit 9b5435f
2 files changed
+12
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
606 | 606 | | |
607 | 607 | | |
608 | 608 | | |
609 | | - | |
| 609 | + | |
610 | 610 | | |
611 | | - | |
612 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
613 | 617 | | |
614 | 618 | | |
615 | 619 | | |
| |||
631 | 635 | | |
632 | 636 | | |
633 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
634 | 641 | | |
635 | 642 | | |
636 | 643 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
| |||
0 commit comments