Skip to content

Commit

Permalink
[osh-language] Try out different 'unset' behavior.
Browse files Browse the repository at this point in the history
It matches bash, mksh, and yash now.  Instead of dash/ash or zsh.

Addresses an issue in #653 (ble.sh).

However this makes some tests in test/spec.sh assign fail.  See the "if
0".
  • Loading branch information
Andy Chu committed Apr 15, 2020
1 parent 6ee1d20 commit aac8712
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
10 changes: 8 additions & 2 deletions core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,14 @@ def Unset(self, lval, lookup_mode, strict):

with tagswitch(lval) as case:
if case(lvalue_e.Named): # unset x
name_map[cell_name].val = value.Undef()
cell.exported = False
if 0: # flip this
# This behavior is good for test/spec.sh assign -r 24-27
name_map[cell_name].val = value.Undef()
cell.exported = False
else:
# This behavior is good for test/spec.sh builtin-vars -r 24 (ble.sh)
del name_map[cell_name]

# This should never happen because we do recursive lookups of namerefs.
assert not cell.nameref, cell

Expand Down
47 changes: 35 additions & 12 deletions spec/builtin-vars.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,46 @@ foo=

#### Unset and scope (bug #653)
unlocal() { unset "$@"; }
check4() {
hello=global

local hello=local
echo hello=$hello
level2() {
local hello=yy

echo level2=$hello
unlocal hello
echo hello=$hello
echo level2=$hello
}
check4
## STDOUT:
hello=local

level1() {
local hello=xx

level2

echo level1=$hello
unlocal hello
echo level1=$hello

level2
}

hello=global
## END
## OK dash/ash/zsh/osh STDOUT:
hello=local
hello=
level1

# bash, mksh, yash agree here.
## STDOUT:
level2=yy
level2=xx
level1=xx
level1=global
level2=yy
level2=global
## END
## OK dash/ash/zsh STDOUT:
level2=yy
level2=
level1=xx
level1=
level2=yy
level2=
## END

#### Unset invalid variable name
Expand Down

0 comments on commit aac8712

Please sign in to comment.