Skip to content

Commit dc9a275

Browse files
committed
Correctly surround binop sides with {} if required
Closes #618
1 parent 5a9d431 commit dc9a275

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Newly generated projects use stdlib v0.9.0.
66
- Additional information is printed to the console when generating HTML
77
documentation from Gleam code.
8+
- Fixed a bug where blocks on either side of a binary operator would be
9+
rendered without `{ }`.
810

911
## v0.9.0-rc1 - 2020-05-26
1012

src/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl<'a> Formatter<'a> {
572572
fn pipe(&mut self, left: &UntypedExpr, right: &UntypedExpr, location_start: usize) -> Document {
573573
let left_precedence = left.binop_precedence();
574574
let right_precedence = right.binop_precedence();
575-
let left = self.expr(left);
575+
let left = self.wrap_expr(left);
576576

577577
// Get comments before right but after left
578578
let comments = self.pop_comments(location_start);
@@ -584,7 +584,7 @@ impl<'a> Formatter<'a> {
584584
..
585585
} => self.pipe_capture_right_hand_side(body),
586586

587-
_ => self.expr(right),
587+
_ => self.wrap_expr(right),
588588
};
589589

590590
// Wrap sides if required

src/format/tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,30 @@ World"
11481148
"#
11491149
);
11501150

1151+
// https://github.com/gleam-lang/gleam/issues/618
1152+
1153+
assert_format!(
1154+
r#"fn main() {
1155+
{
1156+
1
1157+
2
1158+
}
1159+
|> func
1160+
}
1161+
"#
1162+
);
1163+
1164+
assert_format!(
1165+
r#"fn main() {
1166+
1
1167+
|> {
1168+
1
1169+
2
1170+
}
1171+
}
1172+
"#
1173+
);
1174+
11511175
//
11521176
// Let
11531177
//

0 commit comments

Comments
 (0)