Soften the block arity checking (#5135)

This commit is contained in:
JT 2022-04-09 07:57:27 +12:00 committed by GitHub
parent aaec840b91
commit 0b85938415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 25 deletions

View File

@ -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,
},
))
});
}
}

View File

@ -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")
}