From e1177065184d957fab4fc632d5fc21603e482bb4 Mon Sep 17 00:00:00 2001 From: zc he Date: Mon, 13 Jan 2025 22:04:17 +0800 Subject: [PATCH] fix(parser): span of `$it`/`$in` set to the first character of its scope (#14817) # Description Follow-up PR of #14789 The span of `$it/$in` is set to a 0-width one with start/end pointing to the start of its scope, mainly for error messages positioning. # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-parser/src/parser.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index dd11edc974..3d9038856a 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3435,7 +3435,8 @@ pub fn parse_full_signature(working_set: &mut StateWorkingSet, spans: &[Span]) - } pub fn parse_row_condition(working_set: &mut StateWorkingSet, spans: &[Span]) -> Expression { - let var_id = working_set.add_variable(b"$it".to_vec(), Span::unknown(), Type::Any, false); + let pos = spans.first().map(|s| s.start).unwrap_or(0); + let var_id = working_set.add_variable(b"$it".to_vec(), Span::new(pos, pos), Type::Any, false); let expression = parse_math_expression(working_set, spans, Some(var_id)); let span = Span::concat(spans); @@ -6633,7 +6634,12 @@ fn wrap_expr_with_collect(working_set: &mut StateWorkingSet, expr: Expression) - // IN_VARIABLE_ID should get replaced with a unique variable, so that we don't have to // execute as a closure - let var_id = working_set.add_variable(b"$in".into(), Span::unknown(), Type::Any, false); + let var_id = working_set.add_variable( + b"$in".into(), + Span::new(span.start, span.start), + Type::Any, + false, + ); let mut expr = expr.clone(); expr.replace_in_variable(working_set, var_id);