diff --git a/crates/nu-parser/src/type_check.rs b/crates/nu-parser/src/type_check.rs index ad91fd861e..64aa8f0432 100644 --- a/crates/nu-parser/src/type_check.rs +++ b/crates/nu-parser/src/type_check.rs @@ -332,7 +332,7 @@ pub fn math_result_type( (t, Type::List(u)) if type_compatible(t, u) => (Type::Bool, None), (Type::Int | Type::Float, Type::Range) => (Type::Bool, None), (Type::String, Type::String) => (Type::Bool, None), - (Type::String, Type::Record(_, _)) => (Type::Bool, None), + (Type::String, Type::Record(_)) => (Type::Bool, None), (Type::Unknown, _) => (Type::Bool, None), (_, Type::Unknown) => (Type::Bool, None), @@ -354,7 +354,7 @@ pub fn math_result_type( (t, Type::List(u)) if type_compatible(t, u) => (Type::Bool, None), (Type::Int | Type::Float, Type::Range) => (Type::Bool, None), (Type::String, Type::String) => (Type::Bool, None), - (Type::String, Type::Record(_, _)) => (Type::Bool, None), + (Type::String, Type::Record(_)) => (Type::Bool, None), (Type::Unknown, _) => (Type::Bool, None), (_, Type::Unknown) => (Type::Bool, None), diff --git a/crates/nu-protocol/src/ty.rs b/crates/nu-protocol/src/ty.rs index 9c70210cfe..36011e50ce 100644 --- a/crates/nu-protocol/src/ty.rs +++ b/crates/nu-protocol/src/ty.rs @@ -17,7 +17,7 @@ pub enum Type { List(Box), Number, Nothing, - Record(Vec, Vec), + Record(Vec<(String, Type)>), Table, ValueStream, Unknown, @@ -37,7 +37,15 @@ impl Display for Type { Type::Float => write!(f, "float"), Type::Int => write!(f, "int"), Type::Range => write!(f, "range"), - Type::Record(cols, vals) => write!(f, "record<{}, {:?}>", cols.join(", "), vals), + Type::Record(fields) => write!( + f, + "record<{}>", + fields + .iter() + .map(|(x, y)| format!("{}: {}", x, y.to_string())) + .collect::>() + .join(", "), + ), Type::Table => write!(f, "table"), Type::List(l) => write!(f, "list<{}>", l), Type::Nothing => write!(f, "nothing"), diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 521ce0b29b..03325e096b 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -181,9 +181,12 @@ impl Value { Value::Date { .. } => Type::Date, Value::Range { .. } => Type::Range, Value::String { .. } => Type::String, - Value::Record { cols, vals, .. } => { - Type::Record(cols.clone(), vals.iter().map(|x| x.get_type()).collect()) - } + Value::Record { cols, vals, .. } => Type::Record( + cols.iter() + .zip(vals.iter()) + .map(|(x, y)| (x.clone(), y.get_type())) + .collect(), + ), Value::List { .. } => Type::List(Box::new(Type::Unknown)), // FIXME Value::Nothing { .. } => Type::Nothing, Value::Block { .. } => Type::Block,