diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 1098e09004..10d06bae51 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -3382,7 +3382,6 @@ fn canonicalize_and_constrain<'a>( } fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result, LoadingProblem> { - println!("-------- parsing {:?}", header.module_id); let mut module_timing = header.module_timing; let parse_start = SystemTime::now(); let parse_state = parser::State::new(&header.src, Attempting::Module); diff --git a/compiler/parse/src/blankspace.rs b/compiler/parse/src/blankspace.rs index 746719d79e..51cf024397 100644 --- a/compiler/parse/src/blankspace.rs +++ b/compiler/parse/src/blankspace.rs @@ -387,7 +387,9 @@ fn spaces<'a>( ); if any_newlines { state = state.check_indent(min_indent).map_err( - |(fail, _)| (progress, fail, original_state), + |(fail, _)| { + (progress, fail, original_state.clone()) + }, )?; } diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index d436984992..c84143b955 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -596,10 +596,13 @@ fn body<'a>(min_indent: u16) -> impl Parser<'a, Body<'a>> { equals_for_def(), // Spaces after the '=' (at a normal indentation level) and then the expr. // The expr itself must be indented more than the pattern and '=' - space0_before( - loc!(move |arena, state| parse_expr(indented_more, arena, state)), - min_indent, - ) + move |a, s| { + space0_before( + loc!(move |arena, state| { parse_expr(indented_more, arena, state) }), + min_indent, + ) + .parse(a, s) + } ) ); result @@ -1540,7 +1543,8 @@ pub fn if_expr<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>> { ), skip_first!( parser::keyword(keyword::ELSE, min_indent), - space1_around( + // NOTE changed this from space1_around to space1_before + space1_before( loc!(move |arena, state| parse_expr(min_indent, arena, state)), min_indent, ) diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 3deb1ce30e..5c61ad9563 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -2819,6 +2819,31 @@ mod test_parse { assert!(actual.is_ok()); } + #[test] + fn outdenting_newline_after_else() { + use roc_parse::ast::Def::*; + + let arena = Bump::new(); + + // highlights a problem with the else branch demanding a newline after its expression + let src = indoc!( + r#" + main = + v = \y -> if x then y else z + + 1 + "# + ); + + let actual = module_defs() + .parse(&arena, State::new(src.as_bytes(), Attempting::Module)) + .map(|tuple| tuple.1); + + dbg!(&actual); + + assert!(actual.is_ok()); + } + #[test] fn newline_after_equals() { // Regression test for https://github.com/rtfeldman/roc/issues/51