fix(tvix/eval): make sure to force before selecting in catAttrs
Previously, this would almost always crash because list items are thunked more often nowadays and selecting from a thunk would fail. Also we no longer pop from args, accessing it by index should avoid an unnecessary clone here. Change-Id: I4410c4c2e28cc255a2c7cf2a5322db3d2c556a0e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6693 Reviewed-by: grfn <grfn@gws.fyi> Autosubmit: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
151f4437bc
commit
cd280e0796
3 changed files with 17 additions and 5 deletions
|
@ -87,13 +87,14 @@ fn pure_builtins() -> Vec<Builtin> {
|
||||||
Builtin::new("bitXor", &[true, true], |args, _| {
|
Builtin::new("bitXor", &[true, true], |args, _| {
|
||||||
Ok(Value::Integer(args[0].as_int()? ^ args[1].as_int()?))
|
Ok(Value::Integer(args[0].as_int()? ^ args[1].as_int()?))
|
||||||
}),
|
}),
|
||||||
Builtin::new("catAttrs", &[true, true], |mut args, _| {
|
Builtin::new("catAttrs", &[true, true], |args, vm| {
|
||||||
let list = args.pop().unwrap().to_list()?;
|
let key = args[0].to_str()?;
|
||||||
let key = args.pop().unwrap().to_str()?;
|
let list = args[1].to_list()?;
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
|
|
||||||
for set in list.into_iter() {
|
for item in list.into_iter() {
|
||||||
if let Some(value) = set.to_attrs()?.select(key.as_str()) {
|
let set = item.force(vm)?.to_attrs()?;
|
||||||
|
if let Some(value) = set.select(key.as_str()) {
|
||||||
output.push(value.clone());
|
output.push(value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
[ 21 "+" 21 "=" 42 ]
|
|
@ -0,0 +1,10 @@
|
||||||
|
builtins.catAttrs "foo" [
|
||||||
|
{ foo = 21; }
|
||||||
|
{ bar = 23; foo = "+"; }
|
||||||
|
{ }
|
||||||
|
{ bar = 12; }
|
||||||
|
{ foo = 21 + 0; }
|
||||||
|
{ foo = "="; }
|
||||||
|
({ bar = 13; } // { baz = 89; })
|
||||||
|
{ foo = 42; bar = 33; }
|
||||||
|
]
|
Loading…
Reference in a new issue