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

fmt: fix comments between for and { is wrong (fix #15918) (#15919)

This commit is contained in:
shove 2022-09-29 20:26:27 +08:00 committed by GitHub
parent 711bb6def7
commit 63578e63c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -1062,10 +1062,15 @@ pub fn (mut f Fmt) for_stmt(node ast.ForStmt) {
if node.label.len > 0 { if node.label.len > 0 {
f.write('$node.label: ') f.write('$node.label: ')
} }
if node.cond is ast.Comment {
f.comments([node.cond])
}
f.write('for ') f.write('for ')
f.expr(node.cond) if node.cond !is ast.Comment {
if !node.is_inf { f.expr(node.cond)
f.write(' ') if !node.is_inf {
f.write(' ')
}
} }
f.write('{') f.write('{')
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line { if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {

View File

@ -103,3 +103,8 @@ fn between_if_branches() {
else { else {
} }
} }
// comments
for {
break
}

View File

@ -87,3 +87,8 @@ fn between_if_branches() {
else { else {
} }
} }
for // comments
{
break
}