diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 0dcd5b0230..86558acecc 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -3808,7 +3808,9 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str } else { g.write(cond_var) g.write(' == ') + g.write('(') g.expr(expr) + g.write(')') } } if is_expr && tmp_var.len == 0 { diff --git a/vlib/v/tests/match_with_complex_exprs_in_branches_test.v b/vlib/v/tests/match_with_complex_exprs_in_branches_test.v index 037dd31529..7289b101f6 100644 --- a/vlib/v/tests/match_with_complex_exprs_in_branches_test.v +++ b/vlib/v/tests/match_with_complex_exprs_in_branches_test.v @@ -4,7 +4,9 @@ fn test_match_with_array_map_in_branches() { arr := Arr([0, 1]) ret := match arr { []int { - arr.map(fn(s int) string { return s.str() }).str() + arr.map(fn (s int) string { + return s.str() + }).str() } else { '' @@ -29,3 +31,14 @@ fn test_match_expr_of_multi_expr_stmts() { println(ret) assert ret == 2 } + +fn test_match_expression_on_complex_bool_conditions() { + s := 'hello' + x := match true { + s[1] == `e` { 'first' } + (s[1] == `e`) { 'second' } + else { 'not found' } + } + println(x) + assert x == 'first' +}