diff --git a/crates/compiler/parse/src/expr.rs b/crates/compiler/parse/src/expr.rs index 757af05a69..ff6d8e83d2 100644 --- a/crates/compiler/parse/src/expr.rs +++ b/crates/compiler/parse/src/expr.rs @@ -346,6 +346,7 @@ fn parse_expr_start<'a>( loc!(move |a, s, m| parse_expr_operator_chain(m, options, a, s)), fail_expr_start_e() ] + .trace("expr_start") .parse(arena, state, min_indent) } @@ -2076,10 +2077,10 @@ mod when { parser::keyword_e(keyword::IS, EWhen::Is) ) ), - move |arena, state, progress, (case_indent, loc_condition), min_indent| { + move |arena, state, _progress, (case_indent, loc_condition), min_indent| { if case_indent < min_indent { return Err(( - progress, + MadeProgress, // TODO maybe pass case_indent here? EWhen::PatternAlignment(5, state.pos()), state, @@ -2089,15 +2090,18 @@ mod when { // Everything in the branches must be indented at least as much as the case itself. let min_indent = case_indent; - let (p1, branches, state) = branches(options).parse(arena, state, min_indent)?; + let (_p1, branches, state) = branches(options) + .parse(arena, state, min_indent) + .map_err(|(_p, e, s)| (MadeProgress, e, s))?; Ok(( - progress.or(p1), + MadeProgress, Expr::When(arena.alloc(loc_condition), branches.into_bump_slice()), state, )) }, ) + .trace("when") } /// Parsing when with indentation. diff --git a/crates/compiler/parse/src/parser.rs b/crates/compiler/parse/src/parser.rs index d190afd086..328d4b3b0a 100644 --- a/crates/compiler/parse/src/parser.rs +++ b/crates/compiler/parse/src/parser.rs @@ -1380,11 +1380,12 @@ macro_rules! and { macro_rules! one_of { ($p1:expr, $p2:expr) => { move |arena: &'a bumpalo::Bump, state: $crate::state::State<'a>, min_indent: u32| { + let original_state = state.clone(); match $p1.parse(arena, state, min_indent) { valid @ Ok(_) => valid, Err((MadeProgress, fail, state)) => Err((MadeProgress, fail, state)), - Err((NoProgress, _, state)) => $p2.parse(arena, state, min_indent), + Err((NoProgress, _, _)) => $p2.parse(arena, original_state, min_indent), } } }; diff --git a/crates/reporting/tests/test_reporting.rs b/crates/reporting/tests/test_reporting.rs index ccd134d44b..dd7e4d5953 100644 --- a/crates/reporting/tests/test_reporting.rs +++ b/crates/reporting/tests/test_reporting.rs @@ -4837,14 +4837,27 @@ mod test_reporting { "# ), @r###" - ── MISSING EXPRESSION ───────────────────── tmp/pattern_binds_keyword/Test.roc ─ + ── MISSING ARROW ────────────────────────── tmp/pattern_binds_keyword/Test.roc ─ - I am partway through parsing a `when` expression, but I got stuck here: + I am partway through parsing a `when` expression, but got stuck here: 5│ Just when -> - ^ + ^ - I was expecting to see an expression like 42 or "hello". + I was expecting to see an arrow next. + + Note: Sometimes I get confused by indentation, so try to make your `when` + look something like this: + + when List.first plants is + Ok n -> + n + + Err _ -> + 200 + + Notice the indentation. All patterns are aligned, and each branch is + indented a bit more than the corresponding pattern. That is important! "### );