Skip to content

shell/expand: restore array length nounset errors - #785

Merged
ewhauser merged 2 commits into
mainfrom
ewhauser/array-length-nounset
Mar 29, 2026
Merged

ewhauser merged 2 commits into
mainfrom
ewhauser/array-length-nounset

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • restore set -u errors for ${#arr[@]} and ${#arr[*]} on declared-but-unset arrays
  • keep declared-but-unset value and key expansions on their existing empty-output behavior
  • expand shell/expand regression coverage across indexed and associative arrays for [@] and [*]

Why

A recent nounset exemption for declared empty arrays applied to any [@] or [*] subscript before the length-expansion path ran. That changed ${#arr[@]} from Bash-compatible unbound variable failures to 0, which let unset-array length probes silently continue under set -u.

Impact

This restores Bash-compatible nounset behavior for array length probes without changing the current behavior for value and key expansions.

Validation

  • go test ./shell/expand -run 'TestDeclaredEmptyArrayNounset|TestFieldsIndirectUnsetArrayNounset'
  • go test ./shell/expand
  • make lint

@ewhauser
ewhauser marked this pull request as ready for review March 29, 2026 19:23
@ewhauser ewhauser changed the title [codex] shell/expand: restore array length nounset errors shell/expand: restore array length nounset errors Mar 29, 2026
@ewhauser
ewhauser merged commit 9868218 into main Mar 29, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/array-length-nounset branch March 29, 2026 19:39
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.

1 participant