From 1b316be8b29570ca908a0f9bac9e69e057a74b12 Mon Sep 17 00:00:00 2001 From: Daniel Perez Date: Tue, 23 Jul 2024 16:07:20 +0100 Subject: [PATCH] Fix named tuple casting --- src/interpreter/types.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/interpreter/types.rs b/src/interpreter/types.rs index 68a75a9..60cbe06 100644 --- a/src/interpreter/types.rs +++ b/src/interpreter/types.rs @@ -507,6 +507,19 @@ impl Type { HashableIndexMap(new_values), )) } + (Type::NamedTuple(name, types_), Value::NamedTuple(_, kvs)) => { + if kvs.0.keys().ne(types_.0.keys()) { + bail!("named tuple keys do not match") + } + let mut new_values = IndexMap::new(); + for (key, type_) in types_.0.iter() { + new_values.insert(key.clone(), type_.cast(kvs.0.get(key).unwrap())?); + } + Ok(Value::NamedTuple( + name.to_string(), + HashableIndexMap(new_values), + )) + } (Type::Array(t), Value::Array(v, _)) => v .iter() .map(|value| t.cast(value))