mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix missing check for none type on or block on non-option (#17529)
This commit is contained in:
parent
68cab00ded
commit
32751440b6
@ -1160,7 +1160,7 @@ fn (mut c Checker) check_or_last_stmt(stmt ast.Stmt, ret_type ast.Type, expr_ret
|
||||
&& c.table.sym(last_stmt_typ).kind == .voidptr {
|
||||
return
|
||||
}
|
||||
if last_stmt_typ == ast.none_type_idx {
|
||||
if last_stmt_typ == ast.none_type_idx && ret_type.has_flag(.option) {
|
||||
return
|
||||
}
|
||||
type_name := c.table.type_to_str(last_stmt_typ)
|
||||
|
6
vlib/v/checker/tests/wrong_none_on_or_block_err.out
Normal file
6
vlib/v/checker/tests/wrong_none_on_or_block_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/wrong_none_on_or_block_err.vv:8:22: error: wrong return type `none` in the `or {}` block, expected `int`
|
||||
6 | `ő`: 25
|
||||
7 | }
|
||||
8 | println(m[`4`] or { none })
|
||||
| ~~~~
|
||||
9 | }
|
9
vlib/v/checker/tests/wrong_none_on_or_block_err.vv
Normal file
9
vlib/v/checker/tests/wrong_none_on_or_block_err.vv
Normal file
@ -0,0 +1,9 @@
|
||||
module main
|
||||
|
||||
fn main() {
|
||||
m := {
|
||||
`л`: 1
|
||||
`ő`: 25
|
||||
}
|
||||
println(m[`4`] or { none })
|
||||
}
|
Loading…
Reference in New Issue
Block a user