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:
parent
76846fe220
commit
cfe37d36f7
3 changed files with 12 additions and 5 deletions
|
@ -0,0 +1 @@
|
||||||
|
"works fine"
|
|
@ -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"
|
|
@ -182,12 +182,16 @@ impl VM {
|
||||||
|
|
||||||
OpCode::OpAttrOrNotFound => {
|
OpCode::OpAttrOrNotFound => {
|
||||||
let key = self.pop().to_string()?;
|
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()) {
|
_ => Value::NotFound,
|
||||||
Some(value) => self.push(value.clone()),
|
};
|
||||||
None => self.push(Value::NotFound),
|
|
||||||
}
|
self.push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::OpAttrsIsSet => {
|
OpCode::OpAttrsIsSet => {
|
||||||
|
|
Loading…
Reference in a new issue