diff --git a/osh/cmd_eval.py b/osh/cmd_eval.py index 1bec67528..b9dc2edf8 100644 --- a/osh/cmd_eval.py +++ b/osh/cmd_eval.py @@ -208,7 +208,7 @@ def PlusEquals(old_val, val): str_to_append = cast(value.Str, UP_val) val = value.Str(old_val.s + str_to_append.s) - elif tag in (value_e.BashArray, value_e.SparseArray): + elif tag in (value_e.BashArray, value_e.SparseArray, value_e.BashAssoc): e_die("Can't append array to string") else: @@ -236,6 +236,9 @@ def PlusEquals(old_val, val): bash_impl.SparseArray_AppendValues(sparse_lhs, strs) val = sparse_lhs + elif tag == value_e.BashAssoc: + e_die("Can't append an associative array to an indexed array") + else: raise AssertionError() # parsing should prevent this @@ -243,6 +246,9 @@ def PlusEquals(old_val, val): if tag == value_e.Str: e_die("Can't append string to associative arrays") + elif tag in (value_e.BashArray, value_e.SparseArray): + e_die("Can't append an assoxiative array to indexed arrays") + elif tag == value_e.BashAssoc: assoc_lhs = cast(value.BashAssoc, UP_old_val) assoc_rhs = cast(value.BashAssoc, UP_val) diff --git a/spec/append.test.sh b/spec/append.test.sh index 5e90478d2..cb2ba852e 100644 --- a/spec/append.test.sh +++ b/spec/append.test.sh @@ -301,3 +301,29 @@ echo "${e[@]}" ## N-I bash STDOUT: e x ## END + + +#### Type mismatching of lhs+=rhs should not cause a crash +case $SH in mksh|zsh) exit ;; esac +s= +a=() +declare -A d=([lemon]=yellow) + +s+=(1) +s+=([melon]=green) + +a+=lime +a+=([1]=banana) + +d+=orange +d+=(0) + +true + +## STDOUT: +## END + +## OK osh status: 1 + +## N-I mksh/zsh STDOUT: +## END