diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 0b4c229f2c..1c5ca957c9 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) diff --git a/vlib/v/checker/tests/wrong_none_on_or_block_err.out b/vlib/v/checker/tests/wrong_none_on_or_block_err.out new file mode 100644 index 0000000000..30ea39aabe --- /dev/null +++ b/vlib/v/checker/tests/wrong_none_on_or_block_err.out @@ -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 | } diff --git a/vlib/v/checker/tests/wrong_none_on_or_block_err.vv b/vlib/v/checker/tests/wrong_none_on_or_block_err.vv new file mode 100644 index 0000000000..90b834d06b --- /dev/null +++ b/vlib/v/checker/tests/wrong_none_on_or_block_err.vv @@ -0,0 +1,9 @@ +module main + +fn main() { + m := { + `л`: 1 + `ő`: 25 + } + println(m[`4`] or { none }) +}