mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix or_block return &type mismatch (#7138)
This commit is contained in:
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 {
|
match last_stmt {
|
||||||
ast.ExprStmt {
|
ast.ExprStmt {
|
||||||
last_stmt_typ := c.expr(last_stmt.expr)
|
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)
|
is_panic_or_exit := is_expr_panic_or_exit(last_stmt.expr)
|
||||||
if type_fits || is_panic_or_exit {
|
if type_fits || is_panic_or_exit {
|
||||||
return
|
return
|
||||||
|
7
vlib/v/checker/tests/optional_or_block_mismatch.out
Normal file
7
vlib/v/checker/tests/optional_or_block_mismatch.out
Normal file
@ -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 | }
|
12
vlib/v/checker/tests/optional_or_block_mismatch.vv
Normal file
12
vlib/v/checker/tests/optional_or_block_mismatch.vv
Normal file
@ -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
Block a user