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:
parent
1f3428f282
commit
f2c9592b86
@ -607,6 +607,7 @@ mut:
|
|||||||
pub struct AssertStmt {
|
pub struct AssertStmt {
|
||||||
pub:
|
pub:
|
||||||
expr Expr
|
expr Expr
|
||||||
|
pos token.Position
|
||||||
}
|
}
|
||||||
|
|
||||||
// `if [x := opt()] {`
|
// `if [x := opt()] {`
|
||||||
|
@ -274,11 +274,10 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||||||
g.expr(it.expr)
|
g.expr(it.expr)
|
||||||
g.writeln(')) {')
|
g.writeln(')) {')
|
||||||
g.writeln('g_test_fails++;')
|
g.writeln('g_test_fails++;')
|
||||||
g.writeln('puts("FAILED assertion");')
|
g.writeln('puts("FAILED $g.fn_decl.name $it.pos.line_nr");')
|
||||||
g.writeln('puts("function: $g.fn_decl.name");')
|
|
||||||
g.writeln('} else {')
|
g.writeln('} else {')
|
||||||
g.writeln('g_test_oks++;')
|
g.writeln('g_test_oks++;')
|
||||||
g.writeln('puts("OK $g.fn_decl.name");')
|
// g.writeln('puts("OK $g.fn_decl.name");')
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
}
|
}
|
||||||
ast.AssignStmt {
|
ast.AssignStmt {
|
||||||
@ -1216,12 +1215,16 @@ fn (g mut Gen) infix_expr(node ast.InfixExpr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// if node.op == .dot {
|
need_par := node.op == .amp // `x & y == 0` => `(x & y) == 0` in C
|
||||||
// println('!! dot')
|
if need_par {
|
||||||
// }
|
g.write('(')
|
||||||
|
}
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
g.write(' $node.op.str() ')
|
g.write(' $node.op.str() ')
|
||||||
g.expr(node.right)
|
g.expr(node.right)
|
||||||
|
if need_par {
|
||||||
|
g.write(')')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,6 +346,7 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||||||
expr := p.expr(0)
|
expr := p.expr(0)
|
||||||
return ast.AssertStmt{
|
return ast.AssertStmt{
|
||||||
expr: expr
|
expr: expr
|
||||||
|
pos: p.tok.position()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.key_mut {
|
.key_mut {
|
||||||
|
Loading…
Reference in New Issue
Block a user