From 3b51d7cd13b6db7225520a38164b00a3d4dae353 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sun, 15 Jan 2023 10:38:14 -0800 Subject: [PATCH] Fix multi-backpassing in top-level defs Fixes #4821 --- crates/compiler/parse/src/expr.rs | 6 +- ...ackpassing_in_def.moduledefs.formatted.roc | 3 + ...i_backpassing_in_def.moduledefs.result-ast | 67 +++++++++++++++++++ .../multi_backpassing_in_def.moduledefs.roc | 3 + .../test_syntax/tests/test_snapshots.rs | 1 + 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.formatted.roc create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.result-ast create mode 100644 crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.roc diff --git a/crates/compiler/parse/src/expr.rs b/crates/compiler/parse/src/expr.rs index 662ae6ef4f..19df864ced 100644 --- a/crates/compiler/parse/src/expr.rs +++ b/crates/compiler/parse/src/expr.rs @@ -924,7 +924,7 @@ macro_rules! join_alias_to_body { } fn parse_defs_end<'a>( - _options: ExprParseOptions, + options: ExprParseOptions, min_indent: u32, mut defs: Defs<'a>, arena: &'a Bump, @@ -935,7 +935,7 @@ fn parse_defs_end<'a>( loop { let state = global_state; - global_state = match parse_single_def(_options, min_indent, arena, state) { + global_state = match parse_single_def(options, min_indent, arena, state) { Ok((_, Some(single_def), next_state)) => { let region = single_def.region; let spaces_before_current = single_def.spaces_before; @@ -1953,7 +1953,7 @@ pub fn toplevel_defs<'a>() -> impl Parser<'a, Defs<'a>, EExpr<'a>> { let start_column = state.column(); let options = ExprParseOptions { - accept_multi_backpassing: false, + accept_multi_backpassing: true, check_for_arrow: true, }; diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.formatted.roc new file mode 100644 index 0000000000..825368a8d9 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.formatted.roc @@ -0,0 +1,3 @@ +main = + arg1, arg2 <- f {} + "Roc <3 Zig!\n" diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.result-ast new file mode 100644 index 0000000000..f93eedd1bb --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.result-ast @@ -0,0 +1,67 @@ +Defs { + tags: [ + Index(2147483648), + ], + regions: [ + @0-50, + ], + space_before: [ + Slice(start = 0, length = 0), + ], + space_after: [ + Slice(start = 0, length = 0), + ], + spaces: [], + type_defs: [], + value_defs: [ + Body( + @0-4 Identifier( + "main", + ), + @12-50 SpaceBefore( + Backpassing( + [ + @12-16 Identifier( + "arg1", + ), + @18-22 Identifier( + "arg2", + ), + ], + @26-30 Apply( + @26-27 Var { + module_name: "", + ident: "f", + }, + [ + @28-30 Record( + [], + ), + ], + Space, + ), + @35-50 SpaceBefore( + Str( + Line( + [ + Plaintext( + "Roc <3 Zig!", + ), + EscapedChar( + Newline, + ), + ], + ), + ), + [ + Newline, + ], + ), + ), + [ + Newline, + ], + ), + ), + ], +} diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.roc b/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.roc new file mode 100644 index 0000000000..336af68069 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/multi_backpassing_in_def.moduledefs.roc @@ -0,0 +1,3 @@ +main = + arg1, arg2 <- f {} + "Roc <3 Zig!\n" diff --git a/crates/compiler/test_syntax/tests/test_snapshots.rs b/crates/compiler/test_syntax/tests/test_snapshots.rs index cbe46cad68..ae76bcc004 100644 --- a/crates/compiler/test_syntax/tests/test_snapshots.rs +++ b/crates/compiler/test_syntax/tests/test_snapshots.rs @@ -309,6 +309,7 @@ mod test_snapshots { pass/mixed_docs.expr, pass/module_def_newline.moduledefs, pass/multi_backpassing.expr, + pass/multi_backpassing_in_def.moduledefs, pass/multi_backpassing_with_apply.expr, pass/multi_char_string.expr, pass/multiline_string.expr,