IR: fix incorrect capturing of subexpressions

This commit is contained in:
Devyn Cairns 2024-07-26 23:23:34 -07:00
parent 53fbf62493
commit abfe0be537
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View File

@ -444,7 +444,15 @@ pub(crate) fn compile_expression(
working_set,
builder,
&full_cell_path.head,
RedirectModes::capture_out(expr.span),
// Only capture the output if there is a tail. This was a bit of a headscratcher
// as the parser emits a FullCellPath with no tail for subexpressions in
// general, which shouldn't be captured any differently than they otherwise
// would be.
if !full_cell_path.tail.is_empty() {
RedirectModes::capture_out(expr.span)
} else {
redirect_modes
},
in_reg,
out_reg,
)?;

View File

@ -209,6 +209,12 @@ fn run_glob_if_pass_variable_to_external() {
})
}
#[test]
fn subexpression_does_not_implicitly_capture() {
let actual = nu!("(nu --testbin cococo); null");
assert_eq!(actual.out, "cococo");
}
mod it_evaluation {
use super::nu;
use nu_test_support::fs::Stub::{EmptyFile, FileWithContent, FileWithContentToBeTrimmed};