From 863601c2d5ae9551b2ce5262580ace437af94159 Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:56:15 -0800 Subject: [PATCH] Propagate Undefined in object expressions (#171) Signed-off-by: Anand Krishnamoorthi --- src/interpreter.rs | 6 ++++ tests/interpreter/cases/nonstrict/tests.yaml | 35 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/interpreter.rs b/src/interpreter.rs index e00e3f3..b3e68d9 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -1905,7 +1905,13 @@ impl Interpreter { // ( scalar | ref | var ) ":" term, the OPA // implementation is more like expr ":" expr let key = self.eval_expr(key)?; + if key == Value::Undefined { + return Ok(Value::Undefined); + } let value = self.eval_expr(value)?; + if value == Value::Undefined { + return Ok(Value::Undefined); + } object.insert(key, value); } diff --git a/tests/interpreter/cases/nonstrict/tests.yaml b/tests/interpreter/cases/nonstrict/tests.yaml index 665ff13..b20be4c 100644 --- a/tests/interpreter/cases/nonstrict/tests.yaml +++ b/tests/interpreter/cases/nonstrict/tests.yaml @@ -17,3 +17,38 @@ a = to_number("abc") query: data.test error: "could not parse string as number" + + - note: count of null error gobbled up in non strict mode + modules: + - | + package test + import rego.v1 + + foo := input.a + + some_id := { + "count_value": count(foo) > 2, + } + input: + a: null + query: data.test + strict: false + want_result: + foo: null + + - note: count of null error in strict mode + modules: + - | + package test + import rego.v1 + + foo := input.a + + some_id := { + "count_value": count(foo) > 2, + (count(foo) > 2): "count_value", + } + input: + a: null + query: data.test + error: "`count` requires array/object/set/string argument"