From db70c672cf05f78df791ebcb20fa97c4cb786515 Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 15 Oct 2022 20:30:29 +0200 Subject: fix(tvix/eval): don't coerce variable name to string Change-Id: I8aa878dee009901feb453c489ce37c12fa3a31a8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7026 Autosubmit: sterni Reviewed-by: Adam Joseph Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/builtins/impure.rs | 6 +++--- tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index 26422e263002..3d666528e271 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -11,15 +11,15 @@ use std::{ use crate::{ errors::ErrorKind, observer::NoOpObserver, - value::{Builtin, CoercionKind, NixAttrs, NixString, Thunk}, + value::{Builtin, NixAttrs, NixString, Thunk}, vm::VM, SourceCode, Value, }; fn impure_builtins() -> Vec { vec![ - Builtin::new("getEnv", &[true], |args: Vec, vm: &mut VM| { - Ok(env::var(args[0].coerce_to_string(CoercionKind::Weak, vm)?) + Builtin::new("getEnv", &[true], |args: Vec, _: &mut VM| { + Ok(env::var(args[0].to_str()?) .unwrap_or_else(|_| "".into()) .into()) }), diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix new file mode 100644 index 000000000000..fe48a5690c46 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-getEnv-coercion.nix @@ -0,0 +1 @@ +builtins.getEnv { var = "PATH"; __toString = self: self.var; } -- cgit 1.4.1