diff --git a/core/bash_impl.py b/core/bash_impl.py index cfc530baa4..78da8bf685 100644 --- a/core/bash_impl.py +++ b/core/bash_impl.py @@ -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 diff --git a/core/state.py b/core/state.py index c17363cfc4..0ece2292ac 100644 --- a/core/state.py +++ b/core/state.py @@ -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) diff --git a/spec/array.test.sh b/spec/array.test.sh index 08f1784bff..6472798618 100644 --- a/spec/array.test.sh +++ b/spec/array.test.sh @@ -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: