1
0
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:
Felipe Pena 2023-03-07 13:11:03 -03:00 committed by GitHub
parent 68cab00ded
commit 32751440b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -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)

View 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 | }

View File

@ -0,0 +1,9 @@
module main
fn main() {
m := {
`л`: 1
`ő`: 25
}
println(m[`4`] or { none })
}