fix(tvix/eval): ? operator should use OpAttrsOrNotFound

Using `OpAttrSelect`, the ? operator will fail when encountering a
nested value that is not an attribute set.

This however breaks valid code, such as:

  { bs = 42; } ? bs.a.b

The fix is simply to use the same operator used in the `or` statement,
which leaves a sentinal on the stack if a field is not found or the
value is not an attribute set.

Change-Id: Ib28fc8a96e6d592b4cdbc3e65ba129ad8faecd66
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6211
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2022-08-14 14:38:19 +03:00 committed by tazjin
parent cfe37d36f7
commit 3a67f91228
3 changed files with 5 additions and 1 deletions

View file

@ -568,7 +568,7 @@ impl Compiler {
self.compile_with_literal_ident(next)?;
for fragment in fragments.into_iter().rev() {
self.chunk.push_op(OpCode::OpAttrsSelect);
self.chunk.push_op(OpCode::OpAttrOrNotFound);
self.compile_with_literal_ident(fragment)?;
}

View file

@ -0,0 +1 @@
false

View file

@ -0,0 +1,3 @@
# ? operator should work even if encountering a non-set value on the
# walk
{ a.b = 42; } ? a.b.c