Skip to content

Commit c9a8d64

Browse files
fmt: preserve formatting with comments in a empty map (#13362)
1 parent b9fce4e commit c9a8d64

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

vlib/v/fmt/fmt.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,13 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
20972097
f.mark_types_import_as_used(info.key_type)
20982098
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
20992099
}
2100-
f.write('{}')
2100+
if node.pos.line_nr == node.pos.last_line {
2101+
f.write('{}')
2102+
} else {
2103+
f.writeln('{')
2104+
f.comments(node.pre_cmnts, level: .indent)
2105+
f.write('}')
2106+
}
21012107
return
21022108
}
21032109
f.writeln('{')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Foo {
2+
bar map[int]int
3+
}
4+
5+
fn main() {
6+
foo := Foo{
7+
bar: {
8+
// comment
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)