Skip to content

Commit 0e33f6a

Browse files
giacomocavalierilpil
authored andcommitted
do now wrap multiple tuple and field access in a block
1 parent 21e9b91 commit 0e33f6a

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@
189189

190190
### Formatter
191191

192+
- The formatter no longer wraps multiple tuple or field access into a block.
193+
([Giacomo Cavalieri](https://github.com/giacomocavalieri))
194+
192195
### Bug fixes
193196

194197
- The compiler now emits correctly-scoped JavaScript code for `case` expressions

compiler-core/src/format.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,13 +1118,7 @@ impl<'comments> Formatter<'comments> {
11181118

11191119
UntypedExpr::FieldAccess {
11201120
label, container, ..
1121-
} => if let UntypedExpr::TupleIndex { .. } = container.as_ref() {
1122-
self.expr(container).surround("{ ", " }")
1123-
} else {
1124-
self.expr(container)
1125-
}
1126-
.append(".")
1127-
.append(label.as_str()),
1121+
} => self.expr(container).append(".").append(label.as_str()),
11281122

11291123
UntypedExpr::Tuple { elements, location } => self.tuple(elements, location),
11301124

compiler-core/src/format/tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6836,3 +6836,24 @@ pub const list = [
68366836
"
68376837
);
68386838
}
6839+
6840+
// https://github.com/gleam-lang/gleam/issues/5401
6841+
#[test]
6842+
fn multiple_field_access_are_not_put_in_a_block() {
6843+
assert_format!(
6844+
"pub fn main() {
6845+
a.wib.wob
6846+
}
6847+
"
6848+
);
6849+
}
6850+
6851+
#[test]
6852+
fn multiple_tuple_field_access_are_not_put_in_a_block() {
6853+
assert_format!(
6854+
"pub fn main() {
6855+
#(1, 2).1.2
6856+
}
6857+
"
6858+
);
6859+
}

0 commit comments

Comments
 (0)