Skip to content

Commit

Permalink
cgen: fix assert fn_call with parentheses (fix #11207) (#11214)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Aug 17, 2021
1 parent f8174c3 commit e1c762a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vlib/v/gen/c/assert.v
Expand Up @@ -14,9 +14,17 @@ fn (mut g Gen) gen_assert_stmt(original_assert_statement ast.AssertStmt) {
if mut node.expr is ast.InfixExpr {
if mut node.expr.left is ast.CallExpr {
node.expr.left = g.new_ctemp_var_then_gen(node.expr.left, node.expr.left_type)
} else if mut node.expr.left is ast.ParExpr {
if node.expr.left.expr is ast.CallExpr {
node.expr.left = g.new_ctemp_var_then_gen(node.expr.left.expr, node.expr.left_type)
}
}
if mut node.expr.right is ast.CallExpr {
node.expr.right = g.new_ctemp_var_then_gen(node.expr.right, node.expr.right_type)
} else if mut node.expr.right is ast.ParExpr {
if node.expr.right.expr is ast.CallExpr {
node.expr.right = g.new_ctemp_var_then_gen(node.expr.right.expr, node.expr.right_type)
}
}
}
g.inside_ternary++
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/assert_fn_call_with_parentheses_test.v
@@ -0,0 +1,7 @@
fn foo(fail bool) ?string {
return if fail { error('failure') } else { 'success' }
}

fn test_assert_fn_call_with_parentheses() {
assert (foo(true) or { '' }) == ''
}

0 comments on commit e1c762a

Please sign in to comment.