From 384ea111eb19fc311a7be3a5306d7fd598a69bbe Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Tue, 28 Dec 2021 07:04:48 +1100 Subject: [PATCH] Allow for and other commands missing positionals near keywords (#606) * Allow for and other commands missing positionals near keywords * A bit more resilience --- crates/nu-parser/src/parser.rs | 11 +++++++++++ src/tests/test_parser.rs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 8e54d536b6..e932d64c18 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -596,6 +596,17 @@ pub fn parse_internal_call( // spans_idx, end, positional_idx // ); + if spans[..end].is_empty() { + error = error.or_else(|| { + Some(ParseError::MissingPositional( + positional.name.clone(), + spans[spans_idx], + )) + }); + positional_idx += 1; + continue; + } + let orig_idx = spans_idx; let (arg, err) = parse_multispan_value( working_set, diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 0f96c74c14..2bc9b10e84 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -118,3 +118,8 @@ fn long_flag() -> TestResult { fn let_not_statement() -> TestResult { fail_test(r#"let x = "hello" | str length"#, "can't") } + +#[test] +fn for_in_missing_var_name() -> TestResult { + fail_test("for in", "missing") +}