v2 / vlib / v / tests / casts / cast_with_call_in_address_test.v
37 lines · 33 sloc · 490 bytes · c68e37e3e5632ade87cacc98efbc217f9b398f9c
Raw
1@[heap]
2struct Foo {
3mut:
4 val int
5}
6
7@[heap]
8struct Bar {
9mut:
10 val int
11}
12
13interface FooBar {
14mut:
15 val int
16}
17
18fn test_main() {
19 mut fbs := []&FooBar{}
20 fbs << &Foo{1}
21 a := &(fbs[0] as Foo)
22 println(a)
23 b := &(fbs.last() as Foo)
24 println(b)
25 arr1 := [(fbs.last() as Foo)]
26 arr2 := [&(fbs.last() as Foo)]
27 arr3 := [&(get_foo_bar() as Foo)]
28 println(arr1)
29 println(arr2)
30 println(arr3)
31 println(&(fbs.last() as Foo))
32 assert arr2[0] == arr3[0]
33}
34
35fn get_foo_bar() FooBar {
36 return Foo{1}
37}
38