v2 / vlib / v / tests / generics / generics_method_on_embed_struct_test.v
32 lines · 26 sloc · 549 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Context {}
2
3pub fn (mut ctx Context) default_route() string {
4 println('from Context')
5 return 'from Context'
6}
7
8struct App {
9 Context
10}
11
12struct Other {
13 Context
14}
15
16pub fn (mut app Other) default_route() string {
17 println('from Other')
18 return 'from Other'
19}
20
21fn 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
30fn call_generic[T](mut app T) string {
31 return app.default_route()
32}
33