diff --git a/vlib/v/gen/c/assert.v b/vlib/v/gen/c/assert.v index 5390d73bfe..46b48f7f00 100644 --- a/vlib/v/gen/c/assert.v +++ b/vlib/v/gen/c/assert.v @@ -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++ diff --git a/vlib/v/tests/assert_fn_call_with_parentheses_test.v b/vlib/v/tests/assert_fn_call_with_parentheses_test.v new file mode 100644 index 0000000000..4a40c920bf --- /dev/null +++ b/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 { '' }) == '' +}