fix(tvix/eval): or should handle non-attrset values, too

If a nested attrpath encounters a non-set value, the sentinel value
denoting a lack of next values should be emitted. This mirrors the
behaviour of Nix.

Change-Id: Ia80443d5a11243cc6d98dcab1249a3f5fdf77e27
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6210
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-08-14 14:34:53 +03:00 committed by tazjin
parent 76846fe220
commit cfe37d36f7
3 changed files with 12 additions and 5 deletions

View file

@ -0,0 +1 @@
"works fine"

View file

@ -0,0 +1,2 @@
# `or` operator should keep working if it encounters a non-set type.
{ a.b = 42; }.a.b.c or "works fine"

View file

@ -182,12 +182,16 @@ impl VM {
OpCode::OpAttrOrNotFound => {
let key = self.pop().to_string()?;
let attrs = self.pop().to_attrs()?;
let value = match self.pop() {
Value::Attrs(attrs) => match attrs.select(key.as_str()) {
Some(value) => value.clone(),
None => Value::NotFound,
},
match attrs.select(key.as_str()) {
Some(value) => self.push(value.clone()),
None => self.push(Value::NotFound),
}
_ => Value::NotFound,
};
self.push(value);
}
OpCode::OpAttrsIsSet => {