diff --git a/crates/compiler/parse/src/expr.rs b/crates/compiler/parse/src/expr.rs index dde1566e6c..7497d3e0ac 100644 --- a/crates/compiler/parse/src/expr.rs +++ b/crates/compiler/parse/src/expr.rs @@ -1519,7 +1519,7 @@ fn parse_expr_end<'a>( ) -> ParseResult<'a, Expr<'a>, EExpr<'a>> { let parser = skip_first!( crate::blankspace::check_indent(min_indent, EExpr::IndentEnd), - move |a, s| parse_loc_term(min_indent, options, a, s) + move |a, s| parse_loc_term_or_underscore(min_indent, options, a, s) ); match parser.parse(arena, state.clone()) { diff --git a/crates/compiler/parse/tests/snapshots/pass/underscore_in_assignment_pattern.expr.result-ast b/crates/compiler/parse/tests/snapshots/pass/underscore_in_assignment_pattern.expr.result-ast new file mode 100644 index 0000000000..83a3ce5a31 --- /dev/null +++ b/crates/compiler/parse/tests/snapshots/pass/underscore_in_assignment_pattern.expr.result-ast @@ -0,0 +1,231 @@ +Defs( + Defs { + tags: [ + Index(2147483648), + Index(2147483649), + Index(2147483650), + Index(2147483651), + Index(2147483652), + ], + regions: [ + @0-19, + @20-39, + @40-59, + @60-72, + @73-128, + ], + space_before: [ + Slice(start = 0, length = 0), + Slice(start = 0, length = 1), + Slice(start = 1, length = 1), + Slice(start = 2, length = 1), + Slice(start = 3, length = 1), + ], + space_after: [ + Slice(start = 0, length = 0), + Slice(start = 1, length = 0), + Slice(start = 2, length = 0), + Slice(start = 3, length = 0), + Slice(start = 4, length = 0), + ], + spaces: [ + Newline, + Newline, + Newline, + Newline, + ], + type_defs: [], + value_defs: [ + Body( + @0-4 Apply( + @0-4 Tag( + "Pair", + ), + [ + @5-6 Identifier( + "x", + ), + @7-8 Underscore( + "", + ), + ], + ), + @11-19 Apply( + @11-15 Tag( + "Pair", + ), + [ + @16-17 Num( + "0", + ), + @18-19 Num( + "1", + ), + ], + Space, + ), + ), + Body( + @20-28 Apply( + @20-24 Tag( + "Pair", + ), + [ + @25-26 Underscore( + "", + ), + @27-28 Identifier( + "y", + ), + ], + ), + @31-39 Apply( + @31-35 Tag( + "Pair", + ), + [ + @36-37 Num( + "0", + ), + @38-39 Num( + "1", + ), + ], + Space, + ), + ), + Body( + @40-48 Apply( + @40-44 Tag( + "Pair", + ), + [ + @45-46 Underscore( + "", + ), + @47-48 Underscore( + "", + ), + ], + ), + @51-59 Apply( + @51-55 Tag( + "Pair", + ), + [ + @56-57 Num( + "0", + ), + @58-59 Num( + "1", + ), + ], + Space, + ), + ), + Body( + @60-61 Underscore( + "", + ), + @64-72 Apply( + @64-68 Tag( + "Pair", + ), + [ + @69-70 Num( + "0", + ), + @71-72 Num( + "1", + ), + ], + Space, + ), + ), + Body( + @73-98 Apply( + @73-77 Tag( + "Pair", + ), + [ + @79-87 Apply( + @79-83 Tag( + "Pair", + ), + [ + @84-85 Identifier( + "x", + ), + @86-87 Underscore( + "", + ), + ], + ), + @90-98 Apply( + @90-94 Tag( + "Pair", + ), + [ + @95-96 Underscore( + "", + ), + @97-98 Identifier( + "y", + ), + ], + ), + ], + ), + @102-128 Apply( + @102-106 Tag( + "Pair", + ), + [ + @108-116 ParensAround( + Apply( + @108-112 Tag( + "Pair", + ), + [ + @113-114 Num( + "0", + ), + @115-116 Num( + "1", + ), + ], + Space, + ), + ), + @119-127 ParensAround( + Apply( + @119-123 Tag( + "Pair", + ), + [ + @124-125 Num( + "2", + ), + @126-127 Num( + "3", + ), + ], + Space, + ), + ), + ], + Space, + ), + ), + ], + }, + @130-131 SpaceBefore( + Num( + "0", + ), + [ + Newline, + Newline, + ], + ), +) diff --git a/crates/compiler/parse/tests/snapshots/pass/underscore_in_assignment_pattern.expr.roc b/crates/compiler/parse/tests/snapshots/pass/underscore_in_assignment_pattern.expr.roc new file mode 100644 index 0000000000..ee8c61d7e3 --- /dev/null +++ b/crates/compiler/parse/tests/snapshots/pass/underscore_in_assignment_pattern.expr.roc @@ -0,0 +1,7 @@ +Pair x _ = Pair 0 1 +Pair _ y = Pair 0 1 +Pair _ _ = Pair 0 1 +_ = Pair 0 1 +Pair (Pair x _) (Pair _ y) = Pair (Pair 0 1) (Pair 2 3) + +0 diff --git a/crates/compiler/parse/tests/test_parse.rs b/crates/compiler/parse/tests/test_parse.rs index 5b78ca1756..3fb75fc5e3 100644 --- a/crates/compiler/parse/tests/test_parse.rs +++ b/crates/compiler/parse/tests/test_parse.rs @@ -266,6 +266,7 @@ mod test_parse { pass/unary_not_with_parens.expr, pass/unary_not.expr, pass/underscore_backpassing.expr, + pass/underscore_in_assignment_pattern.expr, pass/var_else.expr, pass/var_if.expr, pass/var_is.expr,