From 671915837aee2908431b1d1908352fc0ab9cd628 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 11 Aug 2022 14:56:27 +0300 Subject: fix(tvix/eval): add operation to assert boolean type This operation is required because both sides of the logical operators are strictly evaluated by Nix, even if the resulting value is not used further. For example, in our implementation of `&&`, if the left-hand side is `true`, then the result of the expression is simply the right-hand side value. This value must be asserted to be a boolean for the semantics of the language to work correctly. Change-Id: I34f5364f2a444753fa1d8b0a1a2b2d9cdf7c6700 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6157 Tested-by: BuildkiteCI Reviewed-by: sterni Reviewed-by: grfn --- tvix/eval/src/value/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 4a343797480e..99eb4c657ba5 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -91,6 +91,10 @@ impl Value { }), } } + + pub fn is_bool(&self) -> bool { + matches!(self, Value::Bool(_)) + } } impl Display for Value { -- cgit 1.4.1