| 1 | #include "@VMODROOT/cstruct.h" |
| 2 | |
| 3 | @[typedef] |
| 4 | struct C.Test2 {} |
| 5 | |
| 6 | @[typedef] |
| 7 | struct C.Test1 { |
| 8 | a C.Test2 |
| 9 | } |
| 10 | |
| 11 | fn (s C.Test2) str() string { |
| 12 | return 'test2' |
| 13 | } |
| 14 | |
| 15 | fn (s C.Test1) get() C.Test1 { |
| 16 | return s |
| 17 | } |
| 18 | |
| 19 | fn (s C.Test1) s() string { |
| 20 | return '.${s.get()}.' |
| 21 | } |
| 22 | |
| 23 | type TestAlias = C.Test2 |
| 24 | |
| 25 | fn (s TestAlias) str() string { |
| 26 | return 'test_alias' |
| 27 | } |
| 28 | |
| 29 | fn (s TestAlias) get() TestAlias { |
| 30 | return s |
| 31 | } |
| 32 | |
| 33 | fn test_main() { |
| 34 | x := unsafe { &C.Test1(malloc(1024)) } |
| 35 | println(x) |
| 36 | assert dump('${x}') == '&C.Test1{ |
| 37 | a: test2 |
| 38 | }' |
| 39 | println('.${x.get()}.${x.s()}') |
| 40 | |
| 41 | y := unsafe { &TestAlias(malloc(1024)) } |
| 42 | println(y) |
| 43 | assert dump('${y}') == '&test_alias' |
| 44 | println('.${y.get()}.') |
| 45 | |
| 46 | w := TestAlias(*y) |
| 47 | assert dump(w.str()) == 'test_alias' |
| 48 | |
| 49 | assert true |
| 50 | } |
| 51 | |