diff --git a/crates/compiler/fmt/src/def.rs b/crates/compiler/fmt/src/def.rs index 59c48747fc..fab2b42983 100644 --- a/crates/compiler/fmt/src/def.rs +++ b/crates/compiler/fmt/src/def.rs @@ -1039,6 +1039,7 @@ pub fn fmt_body<'a>( && collection.is_empty() && pattern_extracted.before.iter().all(|s| s.is_newline()) && pattern_extracted.after.iter().all(|s| s.is_newline()) + && !matches!(body.extract_spaces().item, Expr::Defs(..)) } else { false }; diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.formatted.roc b/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.formatted.roc new file mode 100644 index 0000000000..bede9093b4 --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.formatted.roc @@ -0,0 +1,4 @@ +{} = + p + t +J \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.result-ast b/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.result-ast new file mode 100644 index 0000000000..a4ffb4063b --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.result-ast @@ -0,0 +1,73 @@ +Defs( + Defs { + tags: [ + EitherIndex(2147483648), + ], + regions: [ + @0-9, + ], + space_before: [ + Slice { start: 0, length: 0 }, + ], + space_after: [ + Slice { start: 0, length: 0 }, + ], + spaces: [], + type_defs: [], + value_defs: [ + Body( + @0-2 RecordDestructure( + [], + ), + @5-9 SpaceBefore( + Defs( + Defs { + tags: [ + EitherIndex(2147483648), + ], + regions: [ + @5-6, + ], + space_before: [ + Slice { start: 0, length: 0 }, + ], + space_after: [ + Slice { start: 0, length: 0 }, + ], + spaces: [], + type_defs: [], + value_defs: [ + Stmt( + @5-6 Var { + module_name: "", + ident: "p", + }, + ), + ], + }, + @8-9 SpaceBefore( + Var { + module_name: "", + ident: "t", + }, + [ + Newline, + ], + ), + ), + [ + Newline, + ], + ), + ), + ], + }, + @10-11 SpaceBefore( + Tag( + "J", + ), + [ + Newline, + ], + ), +) diff --git a/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.roc b/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.roc new file mode 100644 index 0000000000..aed3ebd67c --- /dev/null +++ b/crates/compiler/test_syntax/tests/snapshots/pass/stmts_in_empty_record_assignment.expr.roc @@ -0,0 +1,4 @@ +{}= + p + t +J \ No newline at end of file diff --git a/crates/compiler/test_syntax/tests/test_snapshots.rs b/crates/compiler/test_syntax/tests/test_snapshots.rs index 2024f0419e..caac291677 100644 --- a/crates/compiler/test_syntax/tests/test_snapshots.rs +++ b/crates/compiler/test_syntax/tests/test_snapshots.rs @@ -604,6 +604,7 @@ mod test_snapshots { pass/spaces_inside_empty_list.expr, pass/standalone_module_defs.moduledefs, pass/stmt_parens_minus.expr, + pass/stmts_in_empty_record_assignment.expr, pass/str_block_multiple_newlines.expr, pass/string_without_escape.expr, pass/sub_var_with_spaces.expr,