1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix error when comments inside if and condition. (fix #15914) (#15915)

This commit is contained in:
shove 2022-09-29 14:14:11 +08:00 committed by GitHub
parent 1ff1f23d9a
commit e2cf403ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -86,11 +86,12 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
pub fn (mut f Fmt) comments(comments []ast.Comment, options CommentsOptions) {
mut prev_line := options.prev_line
for i, c in comments {
if options.prev_line > -1 && ((c.pos.line_nr > prev_line && f.out.last_n(1) != '\n')
|| (c.pos.line_nr > prev_line + 1 && f.out.last_n(2) != '\n\n')) {
if options.prev_line > -1
&& ((c.pos.line_nr > prev_line && f.out.len > 1 && f.out.last_n(1) != '\n')
|| (c.pos.line_nr > prev_line + 1 && f.out.len > 2 && f.out.last_n(2) != '\n\n')) {
f.writeln('')
}
if !f.out.last_n(1)[0].is_space() {
if f.out.len > 1 && !f.out.last_n(1)[0].is_space() {
f.write(' ')
}
f.comment(c, options)

View File

@ -0,0 +1,3 @@
// comments
if true {
}

View File

@ -0,0 +1,2 @@
if true /* comments */ {
}