From 34e7bd861ce3976c17e8d11010e13eccaec5ca45 Mon Sep 17 00:00:00 2001 From: Yash Thakur <45539777+ysthakur@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:35:13 -0400 Subject: [PATCH] Fix bug introduced by #13595 (#13658) # Description @devyn found that https://github.com/nushell/nushell/pull/13595, which made ranges be type-checked at parse time, introduced a bug that caused `../foo` to be parsed as a string rather than a command call. This was caused by `parse_range` returning a `Some` despite there being parse errors (`/foo` doesn't match `SyntaxShape::Number`). To go back to the old behavior, `parse_range` now returns `None` anytime there's any parse errors met while parsing the range. Unfortunately, this means that something like `..$foo` will be parsed as a string if `$foo` isn't defined and as a range if it is defined. That was the behavior before #13595, and it should probably be fixed at some point, but I'm just trying to quickly fix the bug. # User-Facing Changes Things should go back to the way they were before #13595, except the type-checking stuff from that PR is still here. # Tests + Formatting Added a test. Reverted another test that tests that `0..<$day` is parsed successfully as a string if the variable isn't defined. # After Submitting --- crates/nu-parser/src/parser.rs | 5 ++++ crates/nu-parser/tests/test_parser.rs | 34 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 742bd2264493..33ecdadd3a20 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1594,6 +1594,7 @@ pub fn parse_number(working_set: &mut StateWorkingSet, span: Span) -> Expression pub fn parse_range(working_set: &mut StateWorkingSet, span: Span) -> Option { trace!("parsing: range"); + let starting_error_count = working_set.parse_errors.len(); // Range follows the following syntax: [][][] // where is ".." @@ -1715,6 +1716,10 @@ pub fn parse_range(working_set: &mut StateWorkingSet, span: Span) -> Option