about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-09T15·56+0300
committertazjin <tazjin@tvl.su>2022-08-13T20·24+0000
commite15bd9aa63d03e95b6151d5b0dbb4d43a1de5901 (patch)
tree44dfb59eb286654229af3b88ba38f5a2c830f4e4
parent175eb975059e5a36444453d7b63839c5339cd003 (diff)
fix(tvix/eval): Fail on duplicate attribute set keys r/4440
Change-Id: I57373ca76d0e25a5d08a8dfce9d5949099326fc0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6104
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
-rw-r--r--tvix/eval/src/errors.rs4
-rw-r--r--tvix/eval/src/vm.rs6
2 files changed, 9 insertions, 1 deletions
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))));