diff --git a/crates/nu-parser/src/lite_parser.rs b/crates/nu-parser/src/lite_parser.rs index 0be57a7c9a..1a89271af2 100644 --- a/crates/nu-parser/src/lite_parser.rs +++ b/crates/nu-parser/src/lite_parser.rs @@ -136,11 +136,15 @@ impl LiteCommand { } pub fn parts_including_redirection(&self) -> impl Iterator + '_ { - self.parts.iter().copied().chain( - self.redirection - .iter() - .flat_map(|redirection| redirection.spans()), - ) + self.parts + .iter() + .copied() + .chain( + self.redirection + .iter() + .flat_map(|redirection| redirection.spans()), + ) + .sorted_unstable_by_key(|a| (a.start, a.end)) } } diff --git a/crates/nu-parser/tests/test_parser.rs b/crates/nu-parser/tests/test_parser.rs index 1ac3d7e900..c0722d64e4 100644 --- a/crates/nu-parser/tests/test_parser.rs +++ b/crates/nu-parser/tests/test_parser.rs @@ -1243,6 +1243,18 @@ fn test_nothing_comparison_eq() { assert!(matches!(&element.expr.expr, Expr::BinaryOp(..))); } +#[rstest] +#[case(b"let a o> file = 1")] +#[case(b"mut a o> file = 1")] +fn test_redirection_inside_letmut_no_panic(#[case] phase: &[u8]) { + let engine_state = EngineState::new(); + let mut working_set = StateWorkingSet::new(&engine_state); + working_set.add_decl(Box::new(Let)); + working_set.add_decl(Box::new(Mut)); + + parse(&mut working_set, None, phase, true); +} + #[rstest] #[case(b"let a = 1 err> /dev/null")] #[case(b"let a = 1 out> /dev/null")]