I have used the index function reliably over the years to pull multiple items from an array (in particular using index(wherecontains()) however I'm now seeing a very odd behavior and I wanted to know if something has changed. In the epxression below I would expect the index function to return a series of nulls followed by the number 3. Instead it reutrns the following: {PK: 1}, {PK: 2}, {PK: 3}, {PK: 4}, {PK: 3}
Using the index statement with a scalar value for the index, ie: just the number 9 instead of the array, causes the expected behavior to occur.
a!localVariables( local!list: { {PK: 1}, {PK: 2}, {PK: 3}, {PK: 4}, {PK: 5}, {PK: 6}, }, { fn!index(local!list, {7, 7, 7, 7, 3 }, {}) } )
Does anyone have any insight about what's happening here?
Note: For more fun you can replace the index statement with:
fn!index(local!list, {-1, 4, -1, 4, -1, -2, -1, -1 }, {}) ==> [PK:1]; [PK:4]; [PK:2]; [PK:4]; [PK:3]; [PK:4]; [PK:5]; [PK:6] fn!index(local!list, {7, 8, 10, 203 }, {}) ==> [PK:1]; [PK:2]; [PK:3]; [PK:4] fn!index(local!list, enumerate(10), {}) ==> [PK:1]; [PK:2]; [PK:2]; [PK:3]; [PK:4]; [PK:5]; [PK:6]; [PK:3]; [PK:4]; [PK:5]
}
)
Discussion posts and replies are publicly visible
It seems like this behavior (caused by some sort of memory corruption, maybe?) is triggered by the empty dictionary. In your first example, you can replace {} with null or {PK:null} and get your expected result.
{}
null
{PK:null}