| 1 | fn test_interface_embedding_complex() { |
| 2 | mut win := &Window{} |
| 3 | ll := &LinearLayout{} |
| 4 | win.initables << ll |
| 5 | win.init() |
| 6 | } |
| 7 | |
| 8 | //---------------------------------- |
| 9 | |
| 10 | @[heap] |
| 11 | pub struct Window { |
| 12 | mut: |
| 13 | initables []Initable |
| 14 | } |
| 15 | |
| 16 | interface Initable { |
| 17 | get_ptr() |
| 18 | mut: |
| 19 | init(&Window) |
| 20 | } |
| 21 | |
| 22 | fn (mut w Window) init() { |
| 23 | for mut i in w.initables { |
| 24 | i.init(w) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | //---------------------------------- |
| 29 | |
| 30 | pub struct ViewBase {} |
| 31 | |
| 32 | pub fn (mut vb ViewBase) init(window &Window) { |
| 33 | dump(@METHOD) |
| 34 | assert false |
| 35 | } |
| 36 | |
| 37 | pub fn (vb ViewBase) get_ptr() {} |
| 38 | |
| 39 | //------------------------------------- |
| 40 | |
| 41 | @[heap] |
| 42 | pub struct ContainerBase { |
| 43 | ViewBase |
| 44 | } |
| 45 | |
| 46 | // want to execute this method |
| 47 | pub fn (mut cb ContainerBase) init(window &Window) { |
| 48 | dump(@METHOD) |
| 49 | assert true |
| 50 | } |
| 51 | |
| 52 | //-------------------------------------- |
| 53 | |
| 54 | @[heap] |
| 55 | pub struct LinearLayout { |
| 56 | ContainerBase |
| 57 | } |
| 58 | |