mirror of
https://github.com/nushell/nushell.git
synced 2025-05-12 14:04:25 +02:00
fix(parser): don't parse closure in block position
This commit is contained in:
parent
cb133ed387
commit
0491803bc7
@ -2034,6 +2034,10 @@ pub fn parse_brace_expr(
|
|||||||
} else {
|
} else {
|
||||||
parse_record(working_set, span)
|
parse_record(working_set, span)
|
||||||
}
|
}
|
||||||
|
} else if matches!(shape, SyntaxShape::Block) {
|
||||||
|
parse_block_expression(working_set, span)
|
||||||
|
} else if matches!(shape, SyntaxShape::MatchBlock) {
|
||||||
|
parse_match_block_expression(working_set, span)
|
||||||
} else if matches!(second_token_contents, Some(TokenContents::Pipe))
|
} else if matches!(second_token_contents, Some(TokenContents::Pipe))
|
||||||
|| matches!(second_token_contents, Some(TokenContents::PipePipe))
|
|| matches!(second_token_contents, Some(TokenContents::PipePipe))
|
||||||
{
|
{
|
||||||
@ -2042,10 +2046,6 @@ pub fn parse_brace_expr(
|
|||||||
parse_full_cell_path(working_set, None, span)
|
parse_full_cell_path(working_set, None, span)
|
||||||
} else if matches!(shape, SyntaxShape::Closure(_)) {
|
} else if matches!(shape, SyntaxShape::Closure(_)) {
|
||||||
parse_closure_expression(working_set, shape, span)
|
parse_closure_expression(working_set, shape, span)
|
||||||
} else if matches!(shape, SyntaxShape::Block) {
|
|
||||||
parse_block_expression(working_set, span)
|
|
||||||
} else if matches!(shape, SyntaxShape::MatchBlock) {
|
|
||||||
parse_match_block_expression(working_set, span)
|
|
||||||
} else if second_token.is_some_and(|c| {
|
} else if second_token.is_some_and(|c| {
|
||||||
c.len() > 3 && c.starts_with(b"...") && (c[3] == b'$' || c[3] == b'{' || c[3] == b'(')
|
c.len() > 3 && c.starts_with(b"...") && (c[3] == b'$' || c[3] == b'{' || c[3] == b'(')
|
||||||
}) {
|
}) {
|
||||||
|
@ -2724,6 +2724,23 @@ mod input_types {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn closure_in_block_position_errors_correctly() {
|
||||||
|
let mut engine_state = EngineState::new();
|
||||||
|
add_declarations(&mut engine_state);
|
||||||
|
|
||||||
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||||
|
let inputs = [
|
||||||
|
r#"if true { || print hi }"#,
|
||||||
|
r#"match true { || print hi }"#,
|
||||||
|
];
|
||||||
|
|
||||||
|
for input in inputs {
|
||||||
|
parse(&mut working_set, None, input.as_bytes(), true);
|
||||||
|
assert!(!working_set.parse_errors.is_empty(), "testing: {input}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn else_errors_correctly() {
|
fn else_errors_correctly() {
|
||||||
let mut engine_state = EngineState::new();
|
let mut engine_state = EngineState::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user