| 1 | struct Encoder {} |
| 2 | |
| 3 | struct Writer {} |
| 4 | |
| 5 | struct APrice {} |
| 6 | |
| 7 | struct Association { |
| 8 | association &Association = unsafe { nil } |
| 9 | price APrice |
| 10 | } |
| 11 | |
| 12 | fn get_value_from_ref[T](val &T) T { |
| 13 | return *val |
| 14 | } |
| 15 | |
| 16 | fn (e &Encoder) encode_struct[U](val U, mut wr Writer) ! { |
| 17 | $for field in U.fields { |
| 18 | $if field.typ is &Association { |
| 19 | assert get_value_from_ref(val.$(field.name)) == Association{ |
| 20 | association: unsafe { nil } |
| 21 | price: APrice{} |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | fn test_main() { |
| 28 | e := Encoder{} |
| 29 | mut sb := Writer{} |
| 30 | |
| 31 | value := Association{ |
| 32 | association: &Association{ |
| 33 | price: APrice{} |
| 34 | } |
| 35 | price: APrice{} |
| 36 | } |
| 37 | |
| 38 | assert get_value_from_ref(&Association{ |
| 39 | price: APrice{} |
| 40 | }) == Association{ |
| 41 | association: unsafe { nil } |
| 42 | price: APrice{} |
| 43 | } |
| 44 | |
| 45 | e.encode_struct(value, mut sb)! |
| 46 | } |
| 47 | |