From e15bd9aa63d03e95b6151d5b0dbb4d43a1de5901 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 9 Aug 2022 18:56:21 +0300 Subject: fix(tvix/eval): Fail on duplicate attribute set keys Change-Id: I57373ca76d0e25a5d08a8dfce9d5949099326fc0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6104 Tested-by: BuildkiteCI Reviewed-by: grfn --- tvix/eval/src/errors.rs | 4 ++++ tvix/eval/src/vm.rs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 118c106215..8a85972923 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -2,6 +2,10 @@ use std::fmt::Display; #[derive(Debug)] pub enum Error { + DuplicateAttrsKey { + key: String, + }, + TypeError { expected: &'static str, actual: &'static str, diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 58ef67cb55..0c8ea4ffd1 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -211,8 +211,12 @@ impl VM { for _ in 0..count { let value = self.pop(); let key = self.pop().as_string()?; // TODO(tazjin): attrpath - attrs.insert(key, value); + + if attrs.insert(key.clone(), value).is_some() { + return Err(Error::DuplicateAttrsKey { key: key.0 }); + } } + // TODO(tazjin): extend_reserve(count) (rust#72631) self.push(Value::Attrs(Rc::new(NixAttrs::Map(attrs)))); -- cgit 1.4.1