Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4354,6 +4354,11 @@ impl Interpreter {
.unwrap()
.locals
.insert(arg.to_string(), String::new());
if flags.assoc {
self.assoc_arrays.entry(arg.to_string()).or_default();
} else if flags.array {
self.arrays.entry(arg.to_string()).or_default();
}
if flags.integer {
self.variables
.insert(format!("_INTEGER_{}", arg), "1".to_string());
Expand Down Expand Up @@ -4438,7 +4443,13 @@ impl Interpreter {
.insert(var_name.to_string(), value.to_string());
}
} else if !is_internal_variable(arg) {
self.insert_variable_checked(arg.to_string(), String::new());
if flags.assoc {
self.assoc_arrays.entry(arg.to_string()).or_default();
} else if flags.array {
self.arrays.entry(arg.to_string()).or_default();
} else {
self.insert_variable_checked(arg.to_string(), String::new());
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/assoc-arrays.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,35 @@ b=2
c=3
### end

### assoc_local_declare_then_assign
myfunc() {
local -A m
m["a"]="1"
m["b"]="2"
echo "count: ${#m[@]}"
for k in "${!m[@]}"; do echo "key=$k"; done | sort
}
myfunc
### expect
count: 2
key=a
key=b
### end

### assoc_local_keys_in_cmdsub
myfunc() {
local -A m
m["a"]="1"
m["b"]="2"
result="$(printf '%s\n' "${!m[@]}" | sort)"
echo "result: [$result]"
}
Comment on lines +191 to +198
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

Issue #875’s repro involves associative array key expansion inside a process substitution nested within a command substitution (result="$(... < <(... ${!m[@]} ...))"). The new assoc_local_keys_in_cmdsub test covers command substitution but not the nested process substitution case; consider adding a spec test that matches the reported pattern to prevent regressions in that scenario.

Copilot uses AI. Check for mistakes.
myfunc
### expect
result: [a
b]
### end

### assoc_iteration
declare -A m
m[a]="1"
Expand Down
Loading