mirror of
https://github.com/vlang/v.git
synced 2025-09-14 09:56:16 -04:00
This commit is contained in:
parent
bfe2cb7d34
commit
582f7be2e1
@ -1284,7 +1284,7 @@ fn (mut c Checker) check_or_last_stmt(mut stmt ast.Stmt, ret_type ast.Type, expr
|
||||
last_stmt_typ := c.expr(mut stmt.expr)
|
||||
|
||||
if last_stmt_typ.has_flag(.option) || last_stmt_typ == ast.none_type {
|
||||
if stmt.expr in [ast.Ident, ast.SelectorExpr, ast.CallExpr, ast.None] {
|
||||
if stmt.expr in [ast.Ident, ast.SelectorExpr, ast.CallExpr, ast.None, ast.CastExpr] {
|
||||
expected_type_name := c.table.type_to_str(ret_type.clear_flags(.option,
|
||||
.result))
|
||||
got_type_name := c.table.type_to_str(last_stmt_typ)
|
||||
|
@ -0,0 +1,13 @@
|
||||
vlib/v/checker/tests/map_index_or_block_type_mismatch_err.vv:4:20: error: `or` block must provide a value of type `int`, not `none`
|
||||
2 | fn index_got_none_from_or_block() {
|
||||
3 | m := map[string]int{}
|
||||
4 | _ = m['key'] or { none }
|
||||
| ~~~~
|
||||
5 | _ = m['key'] or { ?int(none) }
|
||||
6 | }
|
||||
vlib/v/checker/tests/map_index_or_block_type_mismatch_err.vv:5:21: error: `or` block must provide a value of type `int`, not `?int`
|
||||
3 | m := map[string]int{}
|
||||
4 | _ = m['key'] or { none }
|
||||
5 | _ = m['key'] or { ?int(none) }
|
||||
| ~~~~~~~~~
|
||||
6 | }
|
@ -0,0 +1,6 @@
|
||||
// for issue 20390
|
||||
fn index_got_none_from_or_block() {
|
||||
m := map[string]int{}
|
||||
_ = m['key'] or { none }
|
||||
_ = m['key'] or { ?int(none) }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user