mirror of
https://github.com/nushell/nushell.git
synced 2025-02-08 14:40:53 +01:00
Soften the block arity checking (#5135)
This commit is contained in:
parent
aaec840b91
commit
0b85938415
@ -3630,7 +3630,7 @@ pub fn parse_block_expression(
|
|||||||
// TODO: Finish this
|
// TODO: Finish this
|
||||||
if let SyntaxShape::Block(Some(v)) = shape {
|
if let SyntaxShape::Block(Some(v)) = shape {
|
||||||
if let Some((sig, sig_span)) = &signature {
|
if let Some((sig, sig_span)) = &signature {
|
||||||
if sig.num_positionals() != v.len() {
|
if sig.num_positionals() > v.len() {
|
||||||
error = error.or_else(|| {
|
error = error.or_else(|| {
|
||||||
Some(ParseError::Expected(
|
Some(ParseError::Expected(
|
||||||
format!(
|
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,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,16 +330,6 @@ fn proper_missing_param() -> TestResult {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_arity_check1() -> TestResult {
|
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")
|
fail_test(r#"ls | each { |x, y| 1}"#, "expected 1 block parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user