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

cgen: fix () in & exprs

This commit is contained in:
Alexander Medvednikov 2020-03-26 10:44:59 +01:00
parent 1f3428f282
commit f2c9592b86
3 changed files with 11 additions and 6 deletions

View File

@ -607,6 +607,7 @@ mut:
pub struct AssertStmt {
pub:
expr Expr
pos token.Position
}
// `if [x := opt()] {`

View File

@ -274,11 +274,10 @@ fn (g mut Gen) stmt(node ast.Stmt) {
g.expr(it.expr)
g.writeln(')) {')
g.writeln('g_test_fails++;')
g.writeln('puts("FAILED assertion");')
g.writeln('puts("function: $g.fn_decl.name");')
g.writeln('puts("FAILED $g.fn_decl.name $it.pos.line_nr");')
g.writeln('} else {')
g.writeln('g_test_oks++;')
g.writeln('puts("OK $g.fn_decl.name");')
// g.writeln('puts("OK $g.fn_decl.name");')
g.writeln('}')
}
ast.AssignStmt {
@ -1216,12 +1215,16 @@ fn (g mut Gen) infix_expr(node ast.InfixExpr) {
}
}
else {
// if node.op == .dot {
// println('!! dot')
// }
need_par := node.op == .amp // `x & y == 0` => `(x & y) == 0` in C
if need_par {
g.write('(')
}
g.expr(node.left)
g.write(' $node.op.str() ')
g.expr(node.right)
if need_par {
g.write(')')
}
}
}

View File

@ -346,6 +346,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
expr := p.expr(0)
return ast.AssertStmt{
expr: expr
pos: p.tok.position()
}
}
.key_mut {