From 0b859384154150aa6e6f52b2ca97fa1bb10512cf Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sat, 9 Apr 2022 07:57:27 +1200 Subject: [PATCH] Soften the block arity checking (#5135) --- crates/nu-parser/src/parser.rs | 16 +--------------- src/tests/test_parser.rs | 10 ---------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 35db9ec20..5f634e94d 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3630,7 +3630,7 @@ pub fn parse_block_expression( // TODO: Finish this if let SyntaxShape::Block(Some(v)) = shape { if let Some((sig, sig_span)) = &signature { - if sig.num_positionals() != v.len() { + if sig.num_positionals() > v.len() { error = error.or_else(|| { Some(ParseError::Expected( format!( @@ -3657,20 +3657,6 @@ pub fn parse_block_expression( }); } } - } else if !v.is_empty() { - error = error.or_else(|| { - Some(ParseError::Expected( - format!( - "{} block parameter{}", - v.len(), - if v.len() > 1 { "s" } else { "" } - ), - Span { - start: span.start + 1, - end: span.start + 1, - }, - )) - }); } } diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 2c392327f..849865bf1 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -330,16 +330,6 @@ fn proper_missing_param() -> TestResult { #[test] fn block_arity_check1() -> TestResult { - fail_test(r#"ls | each { 1 }"#, "expected 1 block parameter") -} - -#[test] -fn block_arity_check2() -> TestResult { - fail_test(r#"ls | reduce { 1 }"#, "expected 2 block parameters") -} - -#[test] -fn block_arity_check3() -> TestResult { fail_test(r#"ls | each { |x, y| 1}"#, "expected 1 block parameter") }