diff --git a/crates/nu-command/src/filters/sort_by.rs b/crates/nu-command/src/filters/sort_by.rs index 391aebb912..ace5008354 100644 --- a/crates/nu-command/src/filters/sort_by.rs +++ b/crates/nu-command/src/filters/sort_by.rs @@ -282,6 +282,7 @@ Arbitrary Order of Values: Ints Strings Bools + Lists */ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result { @@ -305,6 +306,9 @@ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result Ordering::Equal, + // Floats will always come before Ints (Value::Float { .. }, Value::Int { .. }) => Ordering::Less, (Value::Int { .. }, Value::Float { .. }) => Ordering::Greater, @@ -317,6 +321,10 @@ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result Ordering::Less, (Value::Bool { .. }, Value::Float { .. }) => Ordering::Greater, + // Floats will always come before Lists + (Value::Float { .. }, Value::List { .. }) => Ordering::Less, + (Value::List { .. }, Value::Float { .. }) => Ordering::Greater, + // Ints will always come before strings (Value::Int { .. }, Value::String { .. }) => Ordering::Less, (Value::String { .. }, Value::Int { .. }) => Ordering::Greater, @@ -325,10 +333,22 @@ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result Ordering::Less, (Value::Bool { .. }, Value::Int { .. }) => Ordering::Greater, + // Ints will always come before Lists + (Value::Int { .. }, Value::List { .. }) => Ordering::Less, + (Value::List { .. }, Value::Int { .. }) => Ordering::Greater, + // Strings will always come before Bools (Value::String { .. }, Value::Bool { .. }) => Ordering::Less, (Value::Bool { .. }, Value::String { .. }) => Ordering::Greater, + // Strings will always come before Lists + (Value::String { .. }, Value::List { .. }) => Ordering::Less, + (Value::List { .. }, Value::String { .. }) => Ordering::Greater, + + // Bools will always come before Lists + (Value::Bool { .. }, Value::List { .. }) => Ordering::Less, + (Value::List { .. }, Value::Bool { .. }) => Ordering::Greater, + _ => { let description = format!("not able to compare {:?} with {:?}\n", left, right); return Err(ShellError::TypeMismatch(description, call.head));