| 1 | struct Context {} |
| 2 | |
| 3 | pub fn (mut ctx Context) default_route() string { |
| 4 | println('from Context') |
| 5 | return 'from Context' |
| 6 | } |
| 7 | |
| 8 | struct App { |
| 9 | Context |
| 10 | } |
| 11 | |
| 12 | struct Other { |
| 13 | Context |
| 14 | } |
| 15 | |
| 16 | pub fn (mut app Other) default_route() string { |
| 17 | println('from Other') |
| 18 | return 'from Other' |
| 19 | } |
| 20 | |
| 21 | fn test_generic_method_on_nested_struct() { |
| 22 | mut app := &App{} |
| 23 | ret1 := call_generic(mut app) |
| 24 | assert ret1 == 'from Context' |
| 25 | mut other := &Other{} |
| 26 | ret2 := call_generic(mut other) |
| 27 | assert ret2 == 'from Other' |
| 28 | } |
| 29 | |
| 30 | fn call_generic[T](mut app T) string { |
| 31 | return app.default_route() |
| 32 | } |
| 33 | |