Fix $in in range expressions (#13447)

# Description

Fixes #13441.

I must have forgotten that `Expr::Range` can contain other expressions,
so I wasn't searching for `$in` to replace within it. Easy fix.

# User-Facing Changes
Bug fix, ranges like `6 | 3..$in` work as expected now.

# Tests + Formatting
Added regression test.
This commit is contained in:
Devyn Cairns 2024-07-25 03:28:44 -07:00 committed by GitHub
parent 9f90d611e1
commit 6446f26283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -432,7 +432,17 @@ impl Expression {
Expr::Int(_) => {} Expr::Int(_) => {}
Expr::Float(_) => {} Expr::Float(_) => {}
Expr::Binary(_) => {} Expr::Binary(_) => {}
Expr::Range(_) => {} Expr::Range(range) => {
if let Some(from) = &mut range.from {
from.replace_in_variable(working_set, new_var_id);
}
if let Some(next) = &mut range.next {
next.replace_in_variable(working_set, new_var_id);
}
if let Some(to) = &mut range.to {
to.replace_in_variable(working_set, new_var_id);
}
}
Expr::Var(var_id) | Expr::VarDecl(var_id) => { Expr::Var(var_id) | Expr::VarDecl(var_id) => {
if *var_id == IN_VARIABLE_ID { if *var_id == IN_VARIABLE_ID {
*var_id = new_var_id; *var_id = new_var_id;

View File

@ -75,6 +75,16 @@ fn in_used_twice_and_also_in_pipeline() -> TestResult {
) )
} }
// #13441
#[test]
fn in_used_in_range_from() -> TestResult {
run_test(r#"6 | $in..10 | math sum"#, "40")
}
#[test]
fn in_used_in_range_to() -> TestResult {
run_test(r#"6 | 3..$in | math sum"#, "18")
}
#[test] #[test]
fn help_works_with_missing_requirements() -> TestResult { fn help_works_with_missing_requirements() -> TestResult {
run_test(r#"each --help | lines | length"#, "72") run_test(r#"each --help | lines | length"#, "72")