Native OCaml Rego/OPA policy engine
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-rego: apply_index treats sets as membership and objects by key

- s[v] on a set returns v when present, undefined otherwise.
- o[k] on an object now resolves any value key (numbers, etc.).

+13 -4
+13 -4
lib/eval.ml
··· 145 145 | _ -> raise (Eval_error "unary minus on non-number") 146 146 147 147 let apply_index base idx = 148 - match idx with 149 - | Value.String s -> Value.field s base 150 - | Value.Number n when Float.is_integer n && Float.is_finite n -> 148 + match (base, idx) with 149 + | _, Value.Undefined -> Value.Undefined 150 + | Value.Set xs, _ -> 151 + (* For sets, [s[v]] is set-membership: returns [v] when present 152 + and undefined otherwise. *) 153 + if List.exists (fun v -> Value.compare v idx = 0) xs then idx 154 + else Value.Undefined 155 + | _, Value.String s -> Value.field s base 156 + | _, Value.Number n when Float.is_integer n && Float.is_finite n -> 151 157 Value.index (int_of_float n) base 152 - | Value.Undefined -> Value.Undefined 158 + | Value.Object pairs, _ -> ( 159 + match List.assoc_opt idx pairs with 160 + | Some v -> v 161 + | None -> Value.Undefined) 153 162 | _ -> raise (Eval_error "invalid index type") 154 163 155 164 let trim_chars cs s =