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

cgen: remove the extra generated parentheses of single in_expr (fix #12158) (#12168)

This commit is contained in:
yuyi 2021-10-14 16:38:16 +08:00 committed by GitHub
parent 6f629d1a6a
commit 05885059bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5051,9 +5051,24 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
}
}
else {
g.write('if (')
mut no_needs_par := false
if branch.cond is ast.InfixExpr {
if branch.cond.op == .key_in && branch.cond.left !is ast.InfixExpr
&& branch.cond.right is ast.ArrayInit {
no_needs_par = true
}
}
if no_needs_par {
g.write('if ')
} else {
g.write('if (')
}
g.expr(branch.cond)
g.writeln(') {')
if no_needs_par {
g.writeln(' {')
} else {
g.writeln(') {')
}
}
}
}