nushell/crates/nu-engine/src
Wind 11cdb94699
IR: rasing reasonable error when using subexpression with and operator (#15623)
# Description
Fixes: #15510
I think it's introduced by #14653, which changes `and/or` to `match`
expression.

After looking into `compile_match`, it's important to collect the value
before matching this.
```rust
    // Important to collect it first
    builder.push(Instruction::Collect { src_dst: match_reg }.into_spanned(match_expr.span))?;
```
This pr is going to apply the logic while compiling `and/or` operation.

# User-Facing Changes
The following will raise a reasonable error:
```nushell
> (nu --testbin cococo false) and true
Error: nu:🐚:operator_unsupported_type

  × The 'and' operator does not work on values of type 'string'.
   ╭─[entry #7:1:2]
 1 │ (nu --testbin cococo false) and true
   ·  ─┬                         ─┬─
   ·   │                          ╰── does not support 'string'
   ·   ╰── string
   ╰────
```

# Tests + Formatting
Added 1 test.

# After Submitting
Maybe need to update doc
https://github.com/nushell/nushell.github.io/pull/1876

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
2025-04-25 22:00:20 +08:00
..
compile IR: rasing reasonable error when using subexpression with and operator (#15623) 2025-04-25 22:00:20 +08:00
call_ext.rs Remove duplicate implementations of CallExt::rest (#14484) 2024-12-01 15:03:45 +01:00
closure_eval.rs Make timeit take only closures as an argument (#14483) 2024-12-10 23:08:53 +08:00
column.rs Use Record's public API in a bunch of places (#10927) 2023-11-08 14:24:00 +01:00
command_prelude.rs More precise ErrorKind::NotFound errors (#15149) 2025-02-22 11:42:44 -05:00
documentation.rs finish removing terminal_size dep (#14819) 2025-01-13 07:00:21 -06:00
env.rs More precise ErrorKind::NotFound errors (#15149) 2025-02-22 11:42:44 -05:00
eval_helpers.rs Error on non-zero exit statuses (#13515) 2024-09-07 06:44:26 +00:00
eval_ir.rs reset argument/redirection state after eval_call errors (#15400) 2025-03-26 19:41:16 -04:00
eval.rs preserve variable capture spans in blocks (#15334) 2025-03-20 14:20:28 -04:00
exit.rs Jobs (#14883) 2025-02-25 12:09:52 -05:00
glob_from.rs check signals in nu-glob and ls (#15140) 2025-02-28 19:36:39 +01:00
lib.rs Jobs (#14883) 2025-02-25 12:09:52 -05:00
scope.rs Custom command attributes (#14906) 2025-02-11 06:34:51 -06:00