about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/mod.rs
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-09-13T13·37+0200
committersterni <sternenseemann@systemli.org>2022-09-15T11·47+0000
commitda1d71a4e8e3afee09d8f72b79b6042d4ccbfc2d (patch)
treefbe325478c5e818b824073fab3a2be98c0b1c26f /tvix/eval/src/builtins/mod.rs
parent16da548f93c9e8e9d4771240bb4a1bf14b9665aa (diff)
feat(tvix/eval): implement correct toString behavior r/4857
Implement C++ Nix's `EvalState::coerceToString` minus some of the Path
/ store handling. This is currently only used for `toString` which does
all possible coercions, but we've already prepared the weaker coercion
variant which is e.g. used for builtins that expect string arguments.

`EvalState::coerceToPath` is still missing for builtins that need a
path, but it'll be easy to build on top of this.

Change-Id: I78d15576b18921791d04b6b1e964b951fdef22c6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6571
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r--tvix/eval/src/builtins/mod.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 0fadb738d529..74215cd37c92 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -10,7 +10,7 @@ use std::{
 
 use crate::{
     errors::ErrorKind,
-    value::{Builtin, NixAttrs, NixList, NixString, Value},
+    value::{Builtin, CoercionKind, NixAttrs, NixList, NixString, Value},
 };
 
 use crate::arithmetic_op;
@@ -121,9 +121,9 @@ fn pure_builtins() -> Vec<Builtin> {
             ));
         }),
         Builtin::new("toString", 1, |args, vm| {
-            force!(vm, &args[0], value, {
-                Ok(Value::String(format!("{}", value).into()))
-            })
+            args[0]
+                .coerce_to_string(CoercionKind::Strong, vm)
+                .map(|s| Value::String(s))
         }),
         Builtin::new("typeOf", 1, |args, vm| {
             force!(vm, &args[0], value, {