mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix unchecked optional in match condition (#10041)
This commit is contained in:
parent
8a380f4699
commit
262ef7598d
@ -5206,6 +5206,7 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
||||
// since it is used in c.match_exprs() it saves checking twice
|
||||
node.cond_type = c.table.mktyp(cond_type)
|
||||
c.ensure_type_exists(node.cond_type, node.pos) or { return ast.void_type }
|
||||
c.check_expr_opt_call(node.cond, cond_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
|
||||
|
@ -151,10 +151,18 @@ vlib/v/checker/tests/optional_fn_err.vv:69:18: error: bar() returns an option, s
|
||||
69 | println(arr.any(bar(true)))
|
||||
| ~~~~~~~~~
|
||||
70 | println(arr.all(bar(true)))
|
||||
71 | }
|
||||
71 |
|
||||
vlib/v/checker/tests/optional_fn_err.vv:70:18: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end
|
||||
68 | println(arr.filter(bar(true)))
|
||||
69 | println(arr.any(bar(true)))
|
||||
70 | println(arr.all(bar(true)))
|
||||
| ~~~~~~~~~
|
||||
71 | }
|
||||
71 |
|
||||
72 | match bar(0) {
|
||||
vlib/v/checker/tests/optional_fn_err.vv:72:8: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end
|
||||
70 | println(arr.all(bar(true)))
|
||||
71 |
|
||||
72 | match bar(0) {
|
||||
| ~~~~~~
|
||||
73 | 0 { }
|
||||
74 | else { }
|
||||
|
@ -68,4 +68,9 @@ fn main() {
|
||||
println(arr.filter(bar(true)))
|
||||
println(arr.any(bar(true)))
|
||||
println(arr.all(bar(true)))
|
||||
|
||||
match bar(0) {
|
||||
0 { }
|
||||
else { }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user