Skip to content

Commit

Permalink
[osh-language] Fix ${var=x} to use dynamic scope.
Browse files Browse the repository at this point in the history
Addresses issue #653 (point 13)
  • Loading branch information
Andy Chu committed Mar 15, 2020
1 parent edcc57b commit c0f9c2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ def _EvalBracedVarSub(self, part, part_vals, quoted):
# avoid it.
rhs_str = _DecayPartValuesToString(effect_part_vals,
self.splitter.GetJoinChar())
state.SetLocalString(self.mem, var_name, rhs_str)
state.SetStringDynamic(self.mem, var_name, rhs_str)
return # EARLY RETURN, part_vals mutated

elif effect == effect_e.Error:
Expand Down
14 changes: 14 additions & 0 deletions spec/var-op-test.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,17 @@ echo should not get here
v=foo
echo ${v+v is not unset} ${unset:+is not unset}
## stdout: v is not unset

#### ${var=x} dynamic scope
f() { : "${hello:=x}"; echo $hello; }
f
echo hello=$hello

f() { hello=x; }
f
echo hello=$hello
## STDOUT:
x
hello=x
hello=x
## END

0 comments on commit c0f9c2f

Please sign in to comment.