tests: add optional_method_err.vv
parent
0801f88d0a
commit
37311883c1
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/optional_method_err.vv:17:10: error: inc_to_limit() returns an option, but you missed to add an `or {}` block to it
|
||||
15 | mut a := Abc{}
|
||||
16 | for _ in 0 .. 4 {
|
||||
17 | _ := a.inc_to_limit(2)
|
||||
| ~~~~~~~~~~~~~~~
|
||||
18 | eprintln('a: $a')
|
||||
19 | }
|
|
@ -0,0 +1,20 @@
|
|||
struct Abc {
|
||||
mut:
|
||||
x int
|
||||
}
|
||||
|
||||
fn (mut a Abc) inc_to_limit(max int) ?int {
|
||||
if a.x >= max {
|
||||
return error('x is already $max')
|
||||
}
|
||||
a.x++
|
||||
return a.x
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut a := Abc{}
|
||||
for _ in 0 .. 4 {
|
||||
_ := a.inc_to_limit(2)
|
||||
eprintln('a: $a')
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue