Make ++ operator work with strings and binary values (#8017)

This PR makes `++` (the append operator) work with strings and binary
values. Can now do things like:

```bash
〉"a" ++ "b"
ab
〉0x[01 02] ++ 0x[03]
Length: 3 (0x3) bytes | printable whitespace ascii_other non_ascii
00000000:   01 02 03                                             •••
```

Closes #8015.
This commit is contained in:
Reilly Wood
2023-02-09 10:52:10 -08:00
committed by GitHub
parent 3b6d340603
commit 16b99ed0ba
3 changed files with 35 additions and 0 deletions

View File

@ -2084,6 +2084,15 @@ impl Value {
rhs.insert(0, val.clone());
Ok(Value::List { vals: rhs, span })
}
(Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => Ok(Value::String {
val: lhs.to_string() + rhs,
span,
}),
(Value::Binary { val: lhs, .. }, Value::Binary { val: rhs, .. }) => {
let mut val = lhs.clone();
val.extend(rhs);
Ok(Value::Binary { val, span })
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),