mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: fix bug where duplicated comma is placed before comment in array init (#12281)
This commit is contained in:
@ -1460,7 +1460,8 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
|
|||||||
if cmt.is_inline {
|
if cmt.is_inline {
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
f.comment(cmt, iembed: true)
|
f.comment(cmt, iembed: true)
|
||||||
if cmt.pos.line_nr == expr_pos.last_line && cmt.pos.pos < expr_pos.pos {
|
if !set_comma && cmt.pos.line_nr == expr_pos.last_line
|
||||||
|
&& cmt.pos.pos < expr_pos.pos {
|
||||||
f.write(',')
|
f.write(',')
|
||||||
set_comma = true
|
set_comma = true
|
||||||
} else {
|
} else {
|
||||||
@ -1471,9 +1472,12 @@ pub fn (mut f Fmt) array_init(node ast.ArrayInit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f.write(', ')
|
if !set_comma {
|
||||||
|
f.write(',')
|
||||||
|
set_comma = true
|
||||||
|
}
|
||||||
|
f.write(' ')
|
||||||
f.comment(cmt, iembed: false)
|
f.comment(cmt, iembed: false)
|
||||||
set_comma = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_comment_was_inline = cmt.is_inline
|
last_comment_was_inline = cmt.is_inline
|
||||||
|
9
vlib/v/fmt/tests/array_init_comments_expected.vv
Normal file
9
vlib/v/fmt/tests/array_init_comments_expected.vv
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
v := [
|
||||||
|
0, // 0
|
||||||
|
1, // 1
|
||||||
|
2, // 2
|
||||||
|
// 2-3
|
||||||
|
3, // 3
|
||||||
|
// 4
|
||||||
|
// 5
|
||||||
|
]
|
9
vlib/v/fmt/tests/array_init_comments_input.vv
Normal file
9
vlib/v/fmt/tests/array_init_comments_input.vv
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
v := [
|
||||||
|
0// 0
|
||||||
|
1 // 1
|
||||||
|
2,// 2
|
||||||
|
// 2-3
|
||||||
|
3, // 3
|
||||||
|
// 4
|
||||||
|
/* 5 */
|
||||||
|
]
|
Reference in New Issue
Block a user