prevent panic when parsing incomplete multi-expr (|) matches (#15230)

Fixes #14971, fixes #15229

# User-Facing Changes

Fixes a panic when variable data is accessed after invalid usage of the
`|` separator, which made it impossible to type certain match arms:

```nushell
> match $in { 1 |
Error:   x Main thread panicked.
  |-> at crates/nu-protocol/src/engine/state_delta.rs💯14
  `-> internal error: missing required scope frame
```

# Description

Removes duplicative calls to `exit_scope` from an inner loop when `|`
parse errors are encountered. The outer loop creates and exits scopes
for each match arm.
This commit is contained in:
Solomon 2025-03-04 11:34:34 +00:00 committed by GitHub
parent de7b000505
commit 4779d69de6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -244,6 +244,13 @@ fn match_with_guard_no_expr_after_if() {
assert!(actual.err.contains("Match guard without an expression"));
}
#[test]
fn match_with_or_missing_expr() {
let actual = nu!("match $in { 1 | }");
assert!(actual.err.contains("expected pattern"));
}
#[test]
fn match_with_comment_1() {
Playground::setup("match_with_comment", |dirs, _| {

View File

@ -4680,8 +4680,6 @@ pub fn parse_match_block_expression(working_set: &mut StateWorkingSet, span: Spa
"end of input".into(),
Span::new(output[position - 1].span.end, output[position - 1].span.end),
));
working_set.exit_scope();
break;
}
@ -4695,8 +4693,6 @@ pub fn parse_match_block_expression(working_set: &mut StateWorkingSet, span: Spa
"end of input".into(),
Span::new(output[position - 1].span.end, output[position - 1].span.end),
));
working_set.exit_scope();
break;
} else {
connector = working_set.get_span_contents(output[position].span);