checker: fix or_block return &type mismatch (#7138)
parent
d1281ac6c1
commit
595efbac5b
|
@ -1698,7 +1698,8 @@ pub fn (mut c Checker) check_or_expr(or_expr ast.OrExpr, ret_type table.Type, ex
|
|||
match last_stmt {
|
||||
ast.ExprStmt {
|
||||
last_stmt_typ := c.expr(last_stmt.expr)
|
||||
type_fits := c.check_types(last_stmt_typ, ret_type)
|
||||
type_fits := c.check_types(last_stmt_typ, ret_type) && last_stmt_typ.nr_muls() ==
|
||||
ret_type.nr_muls()
|
||||
is_panic_or_exit := is_expr_panic_or_exit(last_stmt.expr)
|
||||
if type_fits || is_panic_or_exit {
|
||||
return
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/optional_or_block_mismatch.vv:10:18: error: wrong return type `Bar` in the `or {}` block, expected `&Bar`
|
||||
8 |
|
||||
9 | fn main() {
|
||||
10 | x := foo() or { Bar{} }
|
||||
| ~~~
|
||||
11 | println(x)
|
||||
12 | }
|
|
@ -0,0 +1,12 @@
|
|||
module main
|
||||
|
||||
struct Bar {}
|
||||
|
||||
fn foo() ?&Bar {
|
||||
return none
|
||||
}
|
||||
|
||||
fn main() {
|
||||
x := foo() or { Bar{} }
|
||||
println(x)
|
||||
}
|
Loading…
Reference in New Issue