diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 3c00cb3632..8c8415053c 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -255,7 +255,7 @@ pub fn (x Expr) str() string { return '/* $lines.len lines comment */' } else { text := x.text.trim('\x01').trim_space() - return '// $text' + return '´// $text´' } } ComptimeSelector { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 80ab1ba2fc..681dd2b471 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1970,8 +1970,13 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) { f.comment(c, level: .indent, iembed: true) last_line_nr = c.pos.last_line } - if it.exprs.len == 0 && it.pre_cmnts.len > 0 && it.pre_cmnts[0].pos.line_nr != it.pos.line_nr { - f.writeln('') + if it.pre_cmnts.len > 0 { + same_line := it.pre_cmnts[0].pos.line_nr == it.pos.line_nr + if same_line && it.exprs.len > 0 { + f.write(' ') + } else if !same_line && it.exprs.len == 0 { + f.writeln('') + } } for i, expr in it.exprs { line_nr := expr.position().line_nr diff --git a/vlib/v/fmt/tests/comments_embedded_keep.vv b/vlib/v/fmt/tests/comments_embedded_keep.vv index 72ea53a94e..a28f94bb39 100644 --- a/vlib/v/fmt/tests/comments_embedded_keep.vv +++ b/vlib/v/fmt/tests/comments_embedded_keep.vv @@ -10,3 +10,8 @@ fn only_comments_array() { /* 4, */ ] } + +fn array_pre_comments() { + _ := [/* 2, */ 3] + _ := [/* 4, */ /* 5, */ 6] +}