Skip to content

Commit

Permalink
error when closure param lists aren't terminated by | (nushell#14095)
Browse files Browse the repository at this point in the history
Fixes nushell#13757, fixes nushell#9562

# User-Facing Changes

- `unclosed |` is returned for malformed closure parameters:

```
{ |a }
```

- Parameter list closing pipes are highlighted as part of the closure
  • Loading branch information
sgvictorino authored Oct 22, 2024
1 parent 04fed82 commit 3f75b6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4594,14 +4594,15 @@ pub fn parse_closure_expression(
} = token.1
{
end_span = Some(span);
amt_to_skip = token.0;
amt_to_skip += token.0;
break;
}
}

let end_point = if let Some(span) = end_span {
span.end
} else {
working_set.error(ParseError::Unclosed("|".into(), Span::new(end, end)));
end
};

Expand Down
10 changes: 10 additions & 0 deletions tests/repl/test_signatures.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::repl::tests::{fail_test, run_test, TestResult};
use rstest::rstest;

#[test]
fn list_annotations() -> TestResult {
Expand Down Expand Up @@ -375,3 +376,12 @@ fn table_annotations_with_extra_characters() -> TestResult {
let expected = "Extra characters in the parameter name";
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 |")
}

0 comments on commit 3f75b6b

Please sign in to comment.