fmt: use iembed cmts in arrays at line start when exprs come afterwards (#9285)

pull/9290/head
Lukas Neubert 2021-03-13 08:58:50 +01:00 committed by GitHub
parent 24630850a0
commit f648e3f10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -1832,8 +1832,10 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
set_comma = true
}
if cmt.pos.line_nr > expr_pos.last_line {
embed := i + 1 < node.exprs.len
&& node.exprs[i + 1].position().line_nr == cmt.pos.last_line
f.writeln('')
f.comment(cmt, {})
f.comment(cmt, iembed: embed)
} else {
f.write(' ')
f.comment(cmt, iembed: true)

View File

@ -68,3 +68,9 @@ fn keep_real_block_comment() {
'eggs',
]
}
fn comment_at_line_start_with_expressions_after() {
arr := [123456789012345, 234567890123456, 678901234567890, 789012345678901, /* at the end */
345678901234567, /* in between */ 456789012345678,
/* line start */ 567890123456789, 890123456789012]
}