Skip to content

Commit

Permalink
Fix named tuple casting
Browse files Browse the repository at this point in the history
  • Loading branch information
danhper committed Jul 23, 2024
1 parent f73f99e commit 1b316be
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/interpreter/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 1b316be

Please sign in to comment.