Skip to content

Commit

Permalink
[translation] Initialize more vars
Browse files Browse the repository at this point in the history
No more warnings now!
  • Loading branch information
Andy C committed Mar 13, 2024
1 parent dc3fc1a commit c265df5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin/func_eggex.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _Call(self, match, group_arg, blame_loc):
def _GetGroupIndex(group, ops, blame_loc):
# type: (value_t, eggex_ops_t, loc_t) -> int
UP_group = group
group_index = -1

with tagswitch(group) as case:
if case(value_e.Int):
Expand All @@ -104,7 +105,6 @@ def _GetGroupIndex(group, ops, blame_loc):
blame_loc)
elif case2(eggex_ops_e.Yes):
ops = cast(eggex_ops.Yes, UP_ops)
group_index = -1
for i, name in enumerate(ops.capture_names):
if name == group.s:
group_index = i + 1 # 1-based
Expand All @@ -116,6 +116,8 @@ def _GetGroupIndex(group, ops, blame_loc):
else:
# TODO: add method name to this error
raise error.TypeErr(group, 'expected Int or Str', blame_loc)

assert group_index != -1, 'Should have been initialized'
return group_index


Expand Down
2 changes: 2 additions & 0 deletions ysh/expr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def EvalAugmented(self, lval, rhs_val, op, which_scopes):

elif case(value_e.Dict):
obj = cast(value.Dict, UP_obj)
index = -1 # silence C++ warning
key = val_ops.ToStr(lval.index,
'Dict index should be Str',
loc.Missing)
Expand All @@ -253,6 +254,7 @@ def EvalAugmented(self, lval, rhs_val, op, which_scopes):
with tagswitch(obj) as case:
if case(value_e.List):
obj = cast(value.List, UP_obj)
assert index != -1, 'Should have been initialized'
obj.items[index] = new_val_

elif case(value_e.Dict):
Expand Down

0 comments on commit c265df5

Please sign in to comment.