| 1 | struct Container[T] { |
| 2 | mut: |
| 3 | items []T |
| 4 | } |
| 5 | |
| 6 | fn (mut c Container[T]) pop() ?T { |
| 7 | return c.items.pop() |
| 8 | } |
| 9 | |
| 10 | struct Item { |
| 11 | data string |
| 12 | priority int |
| 13 | } |
| 14 | |
| 15 | fn test_generic_array_pop_call() { |
| 16 | mut a1 := Container[int]{ |
| 17 | items: [11, 22] |
| 18 | } |
| 19 | println(a1) |
| 20 | ret1 := a1.pop() or { 0 } |
| 21 | println(ret1) |
| 22 | assert ret1 == 22 |
| 23 | |
| 24 | item1 := Item{'a', 1} |
| 25 | item2 := Item{'b', 2} |
| 26 | mut a2 := Container[Item]{ |
| 27 | items: [item1, item2] |
| 28 | } |
| 29 | println(a2) |
| 30 | ret2 := a2.pop() or { Item{} } |
| 31 | assert ret2 == item2 |
| 32 | } |
| 33 | |