Skip to content

Commit

Permalink
[core refactor] Refactor the code for BashAssoc unset -v a[k]
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 2, 2024
1 parent a61375f commit 1791139
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/bash_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ def BashAssoc_SetElement(assoc_val, key, s):
assoc_val.d[key] = s


def BashAssoc_UnsetElement(assoc_val, key):
# type: (value.BashAssoc, str) -> None

mylib.dict_erase(assoc_val.d, key)


def BashAssoc_ToStrForShellPrint(assoc_val):
# type: (value.BashAssoc) -> str

Expand Down
2 changes: 1 addition & 1 deletion core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ def Unset(self, lval, which_scopes):
# raise error.Runtime("%r isn't an associative array" % lval.name)

val = cast(value.BashAssoc, UP_val)
mylib.dict_erase(val.d, lval.key)
bash_impl.BashAssoc_UnsetElement(val, lval.key)

else:
raise AssertionError(lval)
Expand Down
4 changes: 2 additions & 2 deletions spec/array.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,8 @@ unset -v 'a[-2]'
## END
## STDERR:
unset -v 'a[-2]'
^~~~~
[ stdin ]:4: fatal: Index -2 is out of bounds for array of length 1
^
[ stdin ]:4: a[-2]: Index is out of bounds for array of length 1
## END

## OK bash STDERR:
Expand Down

0 comments on commit 1791139

Please sign in to comment.