diff --git a/vlib/v/checker/tests/optional_method_err.out b/vlib/v/checker/tests/optional_method_err.out new file mode 100644 index 0000000000..51fdc93ebb --- /dev/null +++ b/vlib/v/checker/tests/optional_method_err.out @@ -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 | } diff --git a/vlib/v/checker/tests/optional_method_err.vv b/vlib/v/checker/tests/optional_method_err.vv new file mode 100644 index 0000000000..01cf15bc16 --- /dev/null +++ b/vlib/v/checker/tests/optional_method_err.vv @@ -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') + } +}