mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: add optional_method_err.vv
This commit is contained in:
parent
0801f88d0a
commit
37311883c1
7
vlib/v/checker/tests/optional_method_err.out
Normal file
7
vlib/v/checker/tests/optional_method_err.out
Normal file
@ -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 | }
|
20
vlib/v/checker/tests/optional_method_err.vv
Normal file
20
vlib/v/checker/tests/optional_method_err.vv
Normal file
@ -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
Block a user