mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix optional or_block {none} (#7095)
This commit is contained in:
parent
c1b25dd61d
commit
30da85a4d5
@ -24,7 +24,7 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if got_idx == table.none_type_idx && expected.has_flag(.optional) {
|
if got_idx == table.none_type_idx && expected.has_flag(.optional) {
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
// allow pointers to be initialized with 0. TODO: use none instead
|
// allow pointers to be initialized with 0. TODO: use none instead
|
||||||
if exp_is_ptr && got_idx == table.int_type_idx {
|
if exp_is_ptr && got_idx == table.int_type_idx {
|
||||||
|
7
vlib/v/checker/tests/optional_or_block_none_err.out
Normal file
7
vlib/v/checker/tests/optional_or_block_none_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/optional_or_block_none_err.vv:18:3: error: wrong return type `none` in the `or {}` block, expected `Animal`
|
||||||
|
16 | fn main() {
|
||||||
|
17 | mut dog := new_animal(9) or {
|
||||||
|
18 | none
|
||||||
|
| ~~~~
|
||||||
|
19 | }
|
||||||
|
20 |
|
22
vlib/v/checker/tests/optional_or_block_none_err.vv
Normal file
22
vlib/v/checker/tests/optional_or_block_none_err.vv
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
struct Animal {
|
||||||
|
mut:
|
||||||
|
height byte
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_animal(height byte) ?Animal {
|
||||||
|
if height < 10 {
|
||||||
|
return error('Too small to be an animal!')
|
||||||
|
}
|
||||||
|
|
||||||
|
return Animal{ height: height }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut dog := new_animal(9) or {
|
||||||
|
none
|
||||||
|
}
|
||||||
|
|
||||||
|
println(dog)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user