Skip to content

Commit 16ff9ef

Browse files
giacomocavalierilpil
authored andcommitted
Make sure record update arguments are grouped together by the formatter
1 parent 2b8239d commit 16ff9ef

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Formatter
66

77
- Fixed a bug where the `@internal` annotation wouldn't be displayed.
8+
- Fixed a bug where a record update's arguments would be incorrectly split on
9+
multiple lines.
810

911
## v1.1.0-rc2 - 2024-04-10
1012

compiler-core/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ impl<'comments> Formatter<'comments> {
11491149
let constructor_doc = self.expr(constructor);
11501150
let comments = self.pop_comments(spread.base.location().start);
11511151
let spread_doc = commented("..".to_doc().append(self.expr(&spread.base)), comments);
1152-
let arg_docs = args.iter().map(|a| self.record_update_arg(a));
1152+
let arg_docs = args.iter().map(|a| self.record_update_arg(a).group());
11531153
let all_arg_docs = once(spread_doc).chain(arg_docs);
11541154
constructor_doc.append(wrap_args(all_arg_docs)).group()
11551155
}

compiler-core/src/format/tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5840,6 +5840,21 @@ fn piped_blocks_are_not_needlessly_indented() {
58405840
);
58415841
}
58425842

5843+
// https://github.com/gleam-lang/gleam/issues/2924
5844+
#[test]
5845+
fn record_update_fields_are_not_needlessly_broken() {
5846+
assert_format!(
5847+
r#"pub fn main() {
5848+
Model(
5849+
..model,
5850+
wibble: wibble_wobble_wibble_wobble + 1,
5851+
wobble: Some(wibble_wobble_wibble_wobble),
5852+
)
5853+
}
5854+
"#
5855+
);
5856+
}
5857+
58435858
// https://github.com/gleam-lang/gleam/issues/2890
58445859
#[test]
58455860
fn piped_lists_are_not_needlessly_indented() {

0 commit comments

Comments
 (0)