ITADN

Zsh completion scripts break when ksharrays is enabled (bad output format specification)

#6372Openglk0 创建于 2026-05-10
C-bugA-completionS-triage
G
glk0commented
### Please complete the following tasks - [x] I have searched the [discussions](https://github.com/clap-rs/clap/discussions) - [x] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues ### Rust Version rustc 1.95.0 (59807616e 2026-04-14) (Arch Linux rust 1:1.95.0-1) ### Clap Version 0.25.1 ### Minimal reproducible code Any app created with Clap. Just generate the completion script and run it. ### Steps to reproduce the bug with the above code ```zsh setopt ksharrays source ./your-generated-completion.zsh # ... ``` ### Actual Behaviour When generating zsh completion scripts with Clap, the generated code currently assumes standard zsh array semantics and breaks when the `ksharrays` option is enabled. For example, generated completions contain checks like: ```zsh (( $+functions[_myapp__update_commands] )) || ... ``` With `setopt ksharrays`, sourcing the completion script can fail with errors such as: ```text bad output format specification ``` The issue appears to stem from the fact that `ksharrays` changes several indexing and parameter-expansion behaviors in zsh to be more ksh-compatible. In particular: * normal zsh arrays are 1-based, but `ksharrays` switches them to 0-based * parameter and subscript parsing semantics differ * some idiomatic zsh completion constructs rely on native zsh behavior and are not robust under `ksharrays` The generated completion scripts currently rely on zsh-specific semantics without guarding against `ksharrays`. ### Expected Behaviour * Generated completion scripts should work regardless of whether `ksharrays` is enabled * or the generated script should explicitly ensure the required option state while executing ### Additional Context Possible fixes: 1. Generate scripts that are compatible with both native zsh arrays and `ksharrays` 2. Wrap completion execution with local option handling, for example: ```zsh emulate -L zsh unsetopt ksharrays ``` ### Debug Output _No response_
4 条评论