diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index fb74601f81..4eaffb96ae 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1929,8 +1929,16 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) { } f.expr(expr) if i < it.ecmnts.len && it.ecmnts[i].len > 0 { - f.write(' ') + mut last_cmt := it.ecmnts[i][0] + if last_cmt.pos.line_nr > expr.position().last_line { + f.writeln('') + } else { + f.write(' ') + } for cmt in it.ecmnts[i] { + if cmt.pos.line_nr > last_cmt.pos.last_line { + f.writeln('') + } f.comment(cmt, iembed: true) } } diff --git a/vlib/v/fmt/tests/comments_embedded_keep.vv b/vlib/v/fmt/tests/comments_embedded_keep.vv new file mode 100644 index 0000000000..8a6554f89a --- /dev/null +++ b/vlib/v/fmt/tests/comments_embedded_keep.vv @@ -0,0 +1,12 @@ +fn only_comments_array() { + arr := [ + /* 1, */ + /* 2, */ + /* 3, */ + /* 4, */ + ] + arr2 := [ + /* 1, */ /* 2, *//* 3, */ + /* 4, */ + ] +} diff --git a/vlib/v/fmt/tests/comments_expected.vv b/vlib/v/fmt/tests/comments_expected.vv index 85a7e56eb2..692275012e 100644 --- a/vlib/v/fmt/tests/comments_expected.vv +++ b/vlib/v/fmt/tests/comments_expected.vv @@ -40,7 +40,8 @@ fn main() { e := c // more comments = more good arr := [ - /* block foo bar */ /* inline foo bar */ + /* block foo bar */ + /* inline foo bar */ 0, ] // before arg comment