diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 5710f0cb38..1a8b70bbb2 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -607,6 +607,7 @@ mut: pub struct AssertStmt { pub: expr Expr + pos token.Position } // `if [x := opt()] {` diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 1cb9f7267c..184b8ba0e7 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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(')') + } } } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d25571cc84..aecd8f11ff 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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 {