Also catch zero-index errors when indexing into a command substiution

We had previously added a more helpful error message when a literal zero
index was specified when indexing into an array. This patch extends that
coverage to cases indexing into a command substitution, e.g.

```fish
echo (printf "hello\nworld\n")[0]
```
This commit is contained in:
Mahmoud Al-Qudsi 2020-04-07 20:02:40 -05:00
parent 33bc2bc312
commit c249b1f2f0

View File

@ -649,7 +649,12 @@ static expand_result_t expand_cmdsubst(wcstring input, parser_t &parser,
bad_pos = parse_slice(slice_begin, &slice_end, slice_idx, sub_res.size());
if (bad_pos != 0) {
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
if (tail_begin[bad_pos] == L'0') {
append_syntax_error(errors, slice_begin - in + bad_pos,
L"array indices start at 1, not 0.");
} else {
append_syntax_error(errors, slice_begin - in + bad_pos, L"Invalid index value");
}
return expand_result_t::make_error(STATUS_EXPAND_ERROR);
}