mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-11 00:37:12 +02:00
Add support for negative array indexes
This commit is contained in:
parent
2b4d7535f5
commit
47762a99bb
5
value.go
5
value.go
@ -294,7 +294,10 @@ func (arr *valueArray) index(i *interpreter, index int) (value, error) {
|
|||||||
if 0 <= index && index < arr.length() {
|
if 0 <= index && index < arr.length() {
|
||||||
return i.evaluatePV(arr.elements[index])
|
return i.evaluatePV(arr.elements[index])
|
||||||
}
|
}
|
||||||
return nil, i.Error(fmt.Sprintf("Index %d out of bounds, not within [0, %v)", index, arr.length()))
|
if -arr.length() <= index && index < 0 {
|
||||||
|
return i.evaluatePV(arr.elements[index + arr.length()])
|
||||||
|
}
|
||||||
|
return nil, i.Error(fmt.Sprintf("Index %d out of bounds, not within [%v, %v)", index, -arr.length(), arr.length()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (arr *valueArray) length() int {
|
func (arr *valueArray) length() int {
|
||||||
|
Loading…
Reference in New Issue
Block a user