Skip to content

Negative array index incorrectly returns first element #133

@pd

Description

@pd

In jrsonnet, any negative index of a non-empty array returns the first element. In go-jsonnet, it is an out-of-bounds error.

local xs = [1, 2];

// any negative index in jrsonnet returns xs[0]:
[xs[-1], xs[-2], xs[-42]]

jrsonnet:

[
   1,
   1,
   1
]

go-jsonnet on the same file:

RUNTIME ERROR: Index -1 out of bounds, not within [0, 2)
        bug.jsonnet:4:2-8       thunk from <$>
        Array element 0
        During manifestation

Negative index on an empty array does fail, but with the wrong index value:

[][-1]

jrsonnet:

// array out of bounds: 0 is not within [0,0)

go-jsonnet:

RUNTIME ERROR: Index -1 out of bounds, not within [0, 0)
        bug.jsonnet:1:1-7       $
        During evaluation

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions