fmt: preserve formatting with comments in a empty map (#13362)

pull/13374/head
Vincenzo Palazzo 2022-02-05 09:05:35 +01:00 committed by GitHub
parent b9fce4ef09
commit c9a8d6448d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -2097,7 +2097,13 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
f.mark_types_import_as_used(info.key_type)
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
}
f.write('{}')
if node.pos.line_nr == node.pos.last_line {
f.write('{}')
} else {
f.writeln('{')
f.comments(node.pre_cmnts, level: .indent)
f.write('}')
}
return
}
f.writeln('{')

View File

@ -0,0 +1,11 @@
struct Foo {
bar map[int]int
}
fn main() {
foo := Foo{
bar: {
// comment
}
}
}