diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 760b38a9c9..d890834a7b 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4128,7 +4128,6 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str if is_expr && tmp_var.len == 0 { g.write(' : ') } else { - g.writeln('') g.write_v_source_line_info(branch.pos) g.write('else ') } @@ -4169,7 +4168,8 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str g.stmts_with_tmp_var(branch.stmts, tmp_var) g.expected_cast_type = 0 if g.inside_ternary == 0 { - g.write('}') + g.writeln('}') + g.stmt_path_pos << g.out.len } sumtype_index++ if branch.exprs.len == 0 || sumtype_index == branch.exprs.len { diff --git a/vlib/v/tests/match_with_multi_sumtype_exprs_test.v b/vlib/v/tests/match_with_multi_sumtype_exprs_test.v new file mode 100644 index 0000000000..32f2daab03 --- /dev/null +++ b/vlib/v/tests/match_with_multi_sumtype_exprs_test.v @@ -0,0 +1,37 @@ +struct Empty {} + +type SumType = Empty | int + +fn isok(a SumType, b SumType) bool { + return !(match a { + int { + match b { + int { a == b } + Empty { false } + } + } + Empty { + false + } + } || match a { + int { + match b { + int { a + 10 == b - 10 } + Empty { false } + } + } + Empty { + false + } + }) +} + +fn test_match_with_multi_sumtype_exprs() { + a := SumType(1) + b := SumType(Empty{}) + + res := isok(a, b) + + dump(res) + assert res +}