diff options
| -rw-r--r-- | src/odin/printer/visit.odin | 4 | ||||
| -rw-r--r-- | tools/odinfmt/tests/.snapshots/comp_lit.odin | 7 | ||||
| -rw-r--r-- | tools/odinfmt/tests/random/.snapshots/demo.odin | 37 |
3 files changed, 39 insertions, 9 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index cc48524..891f507 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -2013,7 +2013,9 @@ visit_expr :: proc( p.config.multiline_composite_literals && comp_lit_spans_multiple_lines(v^) should_newline := - can_multiline || contains_comments_in_range(p, v.pos, v.end) + can_multiline || + comp_lit_contains_fields(p, v^) || + contains_comments_in_range(p, v.pos, v.end) should_newline &= (called_from == .Value_Decl || called_from == .Assignment_Stmt || diff --git a/tools/odinfmt/tests/.snapshots/comp_lit.odin b/tools/odinfmt/tests/.snapshots/comp_lit.odin index d771cb0..a2b8a29 100644 --- a/tools/odinfmt/tests/.snapshots/comp_lit.odin +++ b/tools/odinfmt/tests/.snapshots/comp_lit.odin @@ -24,7 +24,12 @@ main :: proc() { 0, 0, } - _ = T{a = 0, b = 0, c = 0, d = 0} + _ = T{ + a = 0, + b = 0, + c = 0, + d = 0, + } _ = T{ a = 0, b = 0, diff --git a/tools/odinfmt/tests/random/.snapshots/demo.odin b/tools/odinfmt/tests/random/.snapshots/demo.odin index ec39d44..a55af51 100644 --- a/tools/odinfmt/tests/random/.snapshots/demo.odin +++ b/tools/odinfmt/tests/random/.snapshots/demo.odin @@ -203,7 +203,11 @@ control_flow :: proc() { } - some_map := map[string]int{"A" = 1, "C" = 9, "B" = 4} + some_map := map[string]int{ + "A" = 1, + "C" = 9, + "B" = 4, + } defer delete(some_map) for key in some_map { fmt.println(key) @@ -535,7 +539,10 @@ struct_type :: proc() { // You can list just a subset of the fields if you specify the // field by name (the order of the named fields does not matter): - v = Vector3{z = 1, y = 2} + v = Vector3{ + z = 1, + y = 2, + } assert(v.x == 0) assert(v.y == 2) assert(v.z == 1) @@ -681,7 +688,9 @@ union_type :: proc() { // See `parametric_polymorphism` procedure for details new_entity :: proc($T: typeid) -> ^Entity { t := new(Entity) - t.derived = T{entity = t} + t.derived = T{ + entity = t, + } return t } @@ -2010,7 +2019,11 @@ constant_literal_expressions :: proc() { using c: Bar, } - FOO_CONST :: Foo{b = 2, a = 1, c = {3, 4}} + FOO_CONST :: Foo{ + b = 2, + a = 1, + c = {3, 4}, + } fmt.println(FOO_CONST.a) @@ -2023,7 +2036,11 @@ constant_literal_expressions :: proc() { fmt.println("-------") - ARRAY_CONST :: [3]int{1 = 4, 2 = 9, 0 = 1} + ARRAY_CONST :: [3]int{ + 1 = 4, + 2 = 9, + 0 = 1, + } fmt.println(ARRAY_CONST[0]) fmt.println(ARRAY_CONST[1]) @@ -2042,7 +2059,10 @@ constant_literal_expressions :: proc() { C, D, } - ENUM_ARRAY_CONST :: [Baz]int{.A ..= .C = 1, .D = 16} + ENUM_ARRAY_CONST :: [Baz]int{ + .A ..= .C = 1, + .D = 16, + } fmt.println(ENUM_ARRAY_CONST[.A]) fmt.println(ENUM_ARRAY_CONST[.B]) @@ -2058,7 +2078,10 @@ constant_literal_expressions :: proc() { D = 16, } #assert(len(Sparse_Baz) < len(#sparse[Sparse_Baz]int)) - SPARSE_ENUM_ARRAY_CONST :: #sparse[Sparse_Baz]int{.A ..= .C = 1, .D = 16} + SPARSE_ENUM_ARRAY_CONST :: #sparse[Sparse_Baz]int{ + .A ..= .C = 1, + .D = 16, + } fmt.println(SPARSE_ENUM_ARRAY_CONST[.A]) fmt.println(SPARSE_ENUM_ARRAY_CONST[.B]) |