diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 90a3ef690a..f99b8ced21 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -482,11 +482,11 @@ fn (var f Fmt) expr(node ast.Expr) { f.wrap_long_line() } f.expr(expr) - if i < it.exprs.len - 1 { - f.write(', ') - } if line_nr < pos.line_nr { + // Previous element was on a different line, add a newline f.writeln('') + } else if i < it.exprs.len - 1 { + f.write(', ') } line_nr = pos.line_nr } diff --git a/vlib/v/fmt/tests/array_newlines_keep.vv b/vlib/v/fmt/tests/array_newlines_keep.vv new file mode 100644 index 0000000000..6d7d4e55aa --- /dev/null +++ b/vlib/v/fmt/tests/array_newlines_keep.vv @@ -0,0 +1,12 @@ +fn make_flag(a, b, c string) string { + return '' +} + +fn main() { + // Set up flags + expected_flags := [ + make_flag('solaris', '-L', '/opt/local/lib') + make_flag('darwin', '-framework', 'Cocoa') + make_flag('windows', '-l', 'gdi32') + ] +}