Skip to content

shell: allow declared empty arrays under nounset - #783

Merged
ewhauser merged 1 commit into
mainfrom
ewhauser/assoc-array-nounset
Mar 29, 2026
Merged

ewhauser merged 1 commit into
mainfrom
ewhauser/assoc-array-nounset

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • treat declared-but-empty indexed and associative arrays as empty for [@]/* style expansion under nounset
  • add expand and interp regressions for length, keys, and value expansion
  • verify the associative-array conformance slice and the upstream Harness skills hook repro

Testing

  • go test ./shell/expand -run "TestDeclaredEmptyArrayNounset|TestFieldsIndirectUnsetArrayNounset"
  • go test ./internal/shell/interp -run "TestDeclaredEmptyArraysStayEmptyUnderNounset|TestNounsetVarOpsReturnStatusOne"
  • go test ./internal/conformance -run "TestConformance/.*/array-assoc.test.sh"

@ewhauser
ewhauser marked this pull request as ready for review March 29, 2026 18:59
@ewhauser
ewhauser merged commit 99b2a2d into main Mar 29, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/assoc-array-nounset branch March 29, 2026 19:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee191f6b0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread shell/expand/param.go
Comment on lines +886 to +888
switch subscriptLit(pe.Index) {
case "@", "*":
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve nounset failure for ${#arr[@]} on unset arrays

nounsetAllowsDeclaredEmptyArray now returns true for any [@]/[*] subscript on an unset declared array, which also suppresses the nounset check for length expansion. That changes set -u; declare -a arr; echo ${#arr[@]} from an unbound-variable error (bash behavior, and what the previous code path produced) to 0, so scripts that rely on nounset to catch unset-array length probes will silently continue. Please restrict this exemption to value/key expansions and keep ${#...[@]}/${#...[*]} as nounset errors.

Useful? React with 👍 / 👎.

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