mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
GH-3060: Support negative index lookups for vectors
This commit is contained in:
parent
cdb9c74054
commit
351e68b66a
3 changed files with 15 additions and 1 deletions
|
@ -2932,7 +2932,13 @@ ValPtr IndexExpr::Fold(Val* v1, Val* v2) const
|
|||
const ListVal* lv = v2->AsListVal();
|
||||
|
||||
if ( lv->Length() == 1 )
|
||||
v = vect->ValAt(lv->Idx(0)->CoerceToUnsigned());
|
||||
{
|
||||
auto index = lv->Idx(0)->CoerceToInt();
|
||||
if ( index < 0 )
|
||||
index = vect->Size() + index;
|
||||
|
||||
v = vect->ValAt(index);
|
||||
}
|
||||
else
|
||||
return index_slice(vect, lv);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue