1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix match error to none (#10245)

This commit is contained in:
yuyi 2021-05-30 00:30:57 +08:00 committed by GitHub
parent 43acda083a
commit e4f6369cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -5332,6 +5332,8 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
cond_type_sym := c.table.get_type_symbol(cond_type)
if cond_type_sym.kind !in [.interface_, .sum_type] {
node.is_sum_type = false
} else {
node.is_sum_type = true
}
c.match_exprs(mut node, cond_type_sym)
c.expected_type = cond_type

View File

@ -0,0 +1,25 @@
fn do_a_thing(i int) ?int {
if i < 0 {
return error("can't be negative")
}
if i == 0 {
return none
}
return i
}
fn test_match_error_to_none() {
i := 0
if r := do_a_thing(i) {
println(r)
} else {
match err {
none {
assert true
}
else {
assert false
}
}
}
}