Propagate Undefined in object expressions (#171)

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2024-03-05 09:56:15 -08:00
committed by GitHub
parent 976c04be8a
commit 863601c2d5
2 changed files with 41 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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"