FIX: presence checks for tuples with NULL values works now.

This commit is contained in:
Jeremy Wall 2019-01-15 18:51:35 -06:00
parent 599ed31414
commit 5b05405618
3 changed files with 13 additions and 0 deletions

View File

@ -179,3 +179,8 @@ assert {
ok = NULL != "string",
desc = "Strings are comparable to null",
};
assert {
ok = (foo in {foo = NULL}),
desc = "Null valued fields are still present in tuple",
};

View File

@ -780,6 +780,7 @@ impl<'a> FileBuilder<'a> {
Expression::Copy(_) => return self.eval_expr(right, scope),
Expression::Call(_) => return self.eval_expr(right, scope),
Expression::Simple(Value::Symbol(ref s)) => {
let scope = scope.clone().use_curr_val();
scope
.lookup_sym(s, true)
.ok_or(Box::new(error::BuildError::new(
@ -789,6 +790,7 @@ impl<'a> FileBuilder<'a> {
)))
}
Expression::Simple(Value::Str(ref s)) => {
let scope = scope.clone().use_curr_val();
scope
.lookup_sym(s, false)
.ok_or(Box::new(error::BuildError::new(
@ -904,6 +906,7 @@ impl<'a> FileBuilder<'a> {
fn eval_binary(&self, def: &BinaryOpDef, scope: &Scope) -> Result<Rc<Val>, Box<dyn Error>> {
let kind = &def.kind;
if let &BinaryExprType::IN = kind {
// TODO Should we support this operation on strings too?
return self.do_element_check(&def.left, &def.right, scope);
};
let left = self.eval_expr(&def.left, scope)?;

View File

@ -56,6 +56,11 @@ impl Scope {
}
}
pub fn use_curr_val(mut self) -> Self {
self.search_curr_val = true;
self
}
/// Spawn a child scope based on the current scope but without the current
/// val set.
pub fn spawn_child(&self) -> Self {