Skip to content

Commit

Permalink
[ysh] Remove BashArray,BashAssoc support for setvar x[obj]
Browse files Browse the repository at this point in the history
They can already be mutated with shell-style

    a[i]=x

We don't support normal expressions, so place expressions are also
invalid.
  • Loading branch information
Andy C committed Aug 27, 2023
1 parent b8d90b3 commit cdbf3cd
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions osh/cmd_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,37 +985,16 @@ def _Dispatch(self, node, cmd_st):
for i, place in enumerate(places):
rval = rhs_vals[i]
UP_place = place
tag = place.tag()

if tag == lvalue_e.ObjIndex:
# setvar mylist[0] = 42
# setvar mydict['key'] = 42
# setvar mylist[0] = 42
# setvar mydict['key'] = 42
if place.tag() == lvalue_e.ObjIndex:
place = cast(lvalue.ObjIndex, UP_place)

obj = place.obj
UP_obj = obj
with tagswitch(obj) as case:
if case(value_e.BashArray):
obj = cast(value.BashArray, UP_obj)
index = val_ops.ToInt(
place.index,
'BashArray index should be Int',
loc.Missing)
r = val_ops.ToStr(
rval, 'RHS should be Str', loc.Missing)
obj.strs[index] = r

elif case(value_e.BashAssoc):
obj = cast(value.BashAssoc, UP_obj)
key = val_ops.ToStr(
place.index, 'BashAssoc index ',
loc.Missing)
r = val_ops.ToStr(
rval, 'BashAssoc index should be Str',
loc.Missing)
obj.d[key] = r

elif case(value_e.List):
if case(value_e.List):
obj = cast(value.List, UP_obj)
index = val_ops.ToInt(
place.index,
Expand Down

0 comments on commit cdbf3cd

Please sign in to comment.