mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix match with multi sumtype exprs (#10377)
This commit is contained in:
parent
3582118b7c
commit
cd464010d4
@ -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 {
|
if is_expr && tmp_var.len == 0 {
|
||||||
g.write(' : ')
|
g.write(' : ')
|
||||||
} else {
|
} else {
|
||||||
g.writeln('')
|
|
||||||
g.write_v_source_line_info(branch.pos)
|
g.write_v_source_line_info(branch.pos)
|
||||||
g.write('else ')
|
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.stmts_with_tmp_var(branch.stmts, tmp_var)
|
||||||
g.expected_cast_type = 0
|
g.expected_cast_type = 0
|
||||||
if g.inside_ternary == 0 {
|
if g.inside_ternary == 0 {
|
||||||
g.write('}')
|
g.writeln('}')
|
||||||
|
g.stmt_path_pos << g.out.len
|
||||||
}
|
}
|
||||||
sumtype_index++
|
sumtype_index++
|
||||||
if branch.exprs.len == 0 || sumtype_index == branch.exprs.len {
|
if branch.exprs.len == 0 || sumtype_index == branch.exprs.len {
|
||||||
|
37
vlib/v/tests/match_with_multi_sumtype_exprs_test.v
Normal file
37
vlib/v/tests/match_with_multi_sumtype_exprs_test.v
Normal file
@ -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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user