v2 / vlib / v / tests / loops / for_in_option_test.v
28 lines · 24 sloc · 481 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1import os
2
3fn test_for_in_option() {
4 for d in os.read_lines(@FILE) or { panic('not found') } {
5 println(d)
6 }
7 assert true
8}
9
10// for issue 20528
11// phenomenon: when the cond expr is SelectorExpr and the type is an array, cgen fails.
12struct Foo {
13 data ?[]int
14}
15
16fn (f Foo) get_first() ?int {
17 for d in f.data or { return none } {
18 return d
19 }
20 return none
21}
22
23fn test_cond_is_selector_array_and_with_or_block() {
24 foo := Foo{
25 data: [1, 2, 3]
26 }
27 assert foo.get_first()? == 1
28}
29