Skip to content
Merged
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
5 changes: 5 additions & 0 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8001,7 +8001,12 @@ impl Interpreter {
}

/// Check if a variable is set (for `set -u` / nounset).
/// Follows nameref indirection so that a nameref pointing to a defined
/// target is considered "set".
fn is_variable_set(&self, name: &str) -> bool {
// Resolve nameref before checking — a nameref whose target exists is "set".
let name = self.resolve_nameref(name);

// Special variables are always "set"
if matches!(
name,
Expand Down
58 changes: 58 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/nameref.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,61 @@ echo $x
hello
world
### end

### nameref_nounset_basic
# basic nameref under set -u (issue #834)
set -u
target="hello"
declare -n ref=target
echo "${ref}"
### expect
hello
### end

### nameref_nounset_local_n
# local -n inside function under set -u
set -u
val="world"
f() {
local -n r=$1
echo "$r"
}
f val
### expect
world
### end

### nameref_nounset_array
# nameref to array under set -u
set -u
arr=(one two three)
declare -n ref=arr
echo "${ref[1]}"
### expect
two
### end

### nameref_nounset_write_through
# nameref write-through under set -u
set -u
target="before"
declare -n ref=target
ref="after"
echo "$target"
### expect
after
### end

### nameref_nounset_harness
# harness pattern: set -euo pipefail with nameref function
set -euo pipefail
get_value() {
local -n out=$1
out="computed"
}
result=""
get_value result
echo "$result"
### expect
computed
### end
Loading