mirror of
https://github.com/nushell/nushell
synced 2025-01-27 04:15:21 +00:00
error when closure param lists aren't terminated by |
(#14095)
Fixes #13757, fixes #9562 # User-Facing Changes - `unclosed |` is returned for malformed closure parameters: ``` { |a } ``` - Parameter list closing pipes are highlighted as part of the closure
This commit is contained in:
parent
04fed82e5e
commit
3f75b6b371
2 changed files with 12 additions and 1 deletions
|
@ -4594,7 +4594,7 @@ pub fn parse_closure_expression(
|
||||||
} = token.1
|
} = token.1
|
||||||
{
|
{
|
||||||
end_span = Some(span);
|
end_span = Some(span);
|
||||||
amt_to_skip = token.0;
|
amt_to_skip += token.0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4602,6 +4602,7 @@ pub fn parse_closure_expression(
|
||||||
let end_point = if let Some(span) = end_span {
|
let end_point = if let Some(span) = end_span {
|
||||||
span.end
|
span.end
|
||||||
} else {
|
} else {
|
||||||
|
working_set.error(ParseError::Unclosed("|".into(), Span::new(end, end)));
|
||||||
end
|
end
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::repl::tests::{fail_test, run_test, TestResult};
|
use crate::repl::tests::{fail_test, run_test, TestResult};
|
||||||
|
use rstest::rstest;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_annotations() -> TestResult {
|
fn list_annotations() -> TestResult {
|
||||||
|
@ -375,3 +376,12 @@ fn table_annotations_with_extra_characters() -> TestResult {
|
||||||
let expected = "Extra characters in the parameter name";
|
let expected = "Extra characters in the parameter name";
|
||||||
fail_test(input, expected)
|
fail_test(input, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
#[case("{ |a $a }")]
|
||||||
|
#[case("{ |a, b $a + $b }")]
|
||||||
|
#[case("do { |a $a } 1")]
|
||||||
|
#[case("do { |a $a } 1 2")]
|
||||||
|
fn closure_param_list_not_terminated(#[case] input: &str) -> TestResult {
|
||||||
|
fail_test(input, "unclosed |")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue