Skip to content

Commit

Permalink
[osh-lang] 'unset' sets a variable back to the 'Undef' (null) value.
Browse files Browse the repository at this point in the history
It used to remove the name from the scope.

Added spec tests that reveal the difference.  Now there are 5 unique
behaviors for case 23 of spec/assign, rather than 6.  OSH behaves like
zsh and smoosh.

Inspired by conversation with Michael Greenberg in issue #329.
  • Loading branch information
Andy Chu committed Jun 10, 2019
1 parent 82f5f73 commit 6da1da1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion osh/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ def Unset(self, lval, lookup_mode):
found = True
if cell.readonly:
return False, found
del namespace[lval.name] # it must be here
namespace[lval.name].val = value.Undef()
return True, found # found
else:
return True, False
Expand Down
76 changes: 61 additions & 15 deletions spec/assign.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -288,38 +288,31 @@ echo "x=$x"
x=temp-binding
x=mutated-temp
x=local
x=mutated-temp
x=
x=global
## END
## OK dash STDOUT:
## BUG dash STDOUT:
x=temp-binding
x=mutated-temp
x=local
x=
x=mutated-temp
## END
## OK bash STDOUT:
## BUG bash STDOUT:
x=temp-binding
x=mutated-temp
x=local
x=global
x=global
## END
## OK mksh STDOUT:
## BUG mksh STDOUT:
x=temp-binding
x=mutated-temp
x=local
x=mutated-temp
x=mutated-temp
## END
## OK zsh STDOUT:
x=temp-binding
x=mutated-temp
x=local
x=
x=global
## END
## OK yash STDOUT:
## BUG yash STDOUT:
# yash has no locals
x=temp-binding
x=mutated-temp
Expand Down Expand Up @@ -347,7 +340,7 @@ echo "x=$x"
## STDOUT:
x=temp-binding
x=mutated-temp
x=global
x=
x=global
## END
## BUG dash/mksh/yash STDOUT:
Expand All @@ -356,10 +349,63 @@ x=mutated-temp
x=
x=
## END
## BUG zsh STDOUT:
## BUG bash STDOUT:
x=temp-binding
x=mutated-temp
x=
x=global
x=global
## END

#### Using ${x-default} after unsetting local shadowing a global
f() {
echo "x=$x"
local x='local'
echo "x=$x"
unset x
echo "- operator = ${x-default}"
echo ":- operator = ${x:-default}"
}
x=global
f
## STDOUT:
x=global
x=local
- operator = default
:- operator = default
## END
## BUG mksh STDOUT:
x=global
x=local
- operator = global
:- operator = global
## END

#### Using ${x-default} after unsetting a temp binding shadowing a global
f() {
echo "x=$x"
local x='local'
echo "x=$x"
unset x
echo "- operator = ${x-default}"
echo ":- operator = ${x:-default}"
}
x=global
x=temp-binding f
## STDOUT:
x=temp-binding
x=local
- operator = default
:- operator = default
## END
## BUG mksh STDOUT:
x=temp-binding
x=local
- operator = temp-binding
:- operator = temp-binding
## END
## BUG bash STDOUT:
x=temp-binding
x=local
- operator = global
:- operator = global
## END

0 comments on commit 6da1da1

Please sign in to comment.