forked from extern/nushell
allow tables in ++ operator (#7051)
This PR closes #6916, which now allows table/table operations on the `++` operator. ``` [[a b]; [1 2]] ++ [[a b]; [1 3]] ╭───┬───┬───╮ │ # │ a │ b │ ├───┼───┼───┤ │ 0 │ 1 │ 2 │ │ 1 │ 1 │ 3 │ ╰───┴───┴───╯ ```
This commit is contained in:
parent
b7e5790cd1
commit
fd503fceaf
@ -509,3 +509,14 @@ fn adding_value_and_list() {
|
|||||||
|
|
||||||
assert_eq!(actual.out, "[1, 3, 5]");
|
assert_eq!(actual.out, "[1, 3, 5]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn adding_tables() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
[[a b]; [1 2]] ++ [[4 5]; [10 11]] | to nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
assert_eq!(actual.out, "[{a: 1, b: 2}, {4: 10, 5: 11}]");
|
||||||
|
}
|
||||||
|
@ -23,7 +23,6 @@ pub fn math_result_type(
|
|||||||
op: &mut Expression,
|
op: &mut Expression,
|
||||||
rhs: &mut Expression,
|
rhs: &mut Expression,
|
||||||
) -> (Type, Option<ParseError>) {
|
) -> (Type, Option<ParseError>) {
|
||||||
//println!("checking: {:?} {:?} {:?}", lhs, op, rhs);
|
|
||||||
match &op.expr {
|
match &op.expr {
|
||||||
Expr::Operator(operator) => match operator {
|
Expr::Operator(operator) => match operator {
|
||||||
Operator::Math(Math::Plus) => match (&lhs.ty, &rhs.ty) {
|
Operator::Math(Math::Plus) => match (&lhs.ty, &rhs.ty) {
|
||||||
@ -84,6 +83,7 @@ pub fn math_result_type(
|
|||||||
(Type::List(Box::new(Type::Any)), None)
|
(Type::List(Box::new(Type::Any)), None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(Type::Table(a), Type::Table(_)) => (Type::Table(a.clone()), None),
|
||||||
_ => {
|
_ => {
|
||||||
*op = Expression::garbage(op.span);
|
*op = Expression::garbage(op.span);
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user