mirror of
https://github.com/nushell/nushell.git
synced 2026-11-24 10:27:07 +08:00
## Description A binary op (`and`/`or`/comparison) whose right-hand side collects `$in` — via `not (…$in…)`, a `[$in…]` list literal, or a subexpression — inside a `where`/closure row condition raised a compiler error: ```nu [1 2] | where true and not $in # Error: nu::compile::register_uninitialized ``` In `compile_binary_op` (`crates/nu-engine/src/compile/operator.rs`), `lhs_reg = out_reg`, so for a `$in`-using binary op the input register aliases the LHS (`in_reg == lhs_reg`). The RHS is compiled with `rhs_in_reg = in_reg`, and several RHS paths in `compile_expression` then call `drop_input`, which emits `Drop` on that register and frees the still-live LHS — so the following `BinaryOp` reads a freed register → `register_uninitialized`. Fix: when the RHS uses `$in` and `in_reg` aliases `lhs_reg`, clone it so the RHS gets its own droppable input register. Applied to both the `and`/`or` and the comparison branches; it fires only on the exact aliasing condition that currently crashes, so all other binary ops are unchanged. This fixes the compiler crash only. Two pre-existing, unrelated runtime issues are out of scope: misusing `$in` (vs `$it`) in a `where` row condition still yields a runtime `variable_not_found`, and `where … in [$in.field]` list-literal `$in` resolution is a separate runtime gap. ## User-facing changes (Release notes) - Fixed a compiler error (`register_uninitialized`) when the right-hand side of an `and`/`or`/comparison collects `$in`, for example `... | where $in.x > 0 and not ($in.x > 5)`. ## Additional notes Fixes #18323. Added a regression test in `tests/eval/`. `cargo fmt --check`, `cargo clippy -p nu-engine`, and the `eval` suite (69 tests) pass. --------- Co-authored-by: max <max@example.com>