| 1 | struct Base { |
| 2 | } |
| 3 | |
| 4 | interface Foo { |
| 5 | parent Foo2 |
| 6 | thing(mut b Base, value i64) string |
| 7 | } |
| 8 | |
| 9 | interface Foo2 { |
| 10 | thing(mut b Base, value i64) string |
| 11 | } |
| 12 | |
| 13 | struct Bar { |
| 14 | parent Foo2 |
| 15 | } |
| 16 | |
| 17 | struct Bar2 {} |
| 18 | |
| 19 | fn (f Bar) thing(mut b Base, value i64) string { |
| 20 | return 'bar' |
| 21 | } |
| 22 | |
| 23 | fn (f Bar2) thing(mut b Base, value i64) string { |
| 24 | return 'bar2' |
| 25 | } |
| 26 | |
| 27 | struct SubBar { |
| 28 | parent Foo2 = Bar2{} |
| 29 | } |
| 30 | |
| 31 | fn (f SubBar) thing(mut b Base, value i64) string { |
| 32 | return 'subbar' |
| 33 | } |
| 34 | |
| 35 | fn test_interface_nested_field() { |
| 36 | mut foo_group := []Foo2{} |
| 37 | foo_group << Bar2{} |
| 38 | foo_group << SubBar{} |
| 39 | |
| 40 | mut b := Base{} |
| 41 | mut ret := []string{} |
| 42 | for foo in foo_group { |
| 43 | println(foo.thing(mut b, 22)) |
| 44 | ret << foo.thing(mut b, 22) |
| 45 | } |
| 46 | assert ret.len == 2 |
| 47 | assert ret[0] == 'bar2' |
| 48 | assert ret[1] == 'subbar' |
| 49 | } |
| 50 | |
| 51 | interface Root { |
| 52 | v View |
| 53 | } |
| 54 | |
| 55 | struct MyRoot { |
| 56 | v View |
| 57 | } |
| 58 | |
| 59 | interface View { |
| 60 | render() int |
| 61 | } |
| 62 | |
| 63 | struct MyView {} |
| 64 | |
| 65 | fn (m MyView) render() int { |
| 66 | return 24 |
| 67 | } |
| 68 | |
| 69 | fn receive_root(r Root) int { |
| 70 | return r.v.render() |
| 71 | } |
| 72 | |
| 73 | fn test_nested_interface_fields() { |
| 74 | assert receive_root(MyRoot{MyView{}}) == 24 |
| 75 | } |
| 76 | |