| 1 | struct Encoder {} |
| 2 | |
| 3 | struct Writer {} |
| 4 | |
| 5 | struct StructTypePointer[T] { |
| 6 | mut: |
| 7 | val &T |
| 8 | } |
| 9 | |
| 10 | pub fn (e &Encoder) encode_value[T](val T, mut wr Writer) ! { |
| 11 | assert e.encode_struct[T](val, 1, mut wr)! == 'a' |
| 12 | } |
| 13 | |
| 14 | fn (e &Encoder) encode_struct[U](val U, level int, mut wr Writer) !string { |
| 15 | $for field in U.fields { |
| 16 | if val.$(field.name) != unsafe { nil } { |
| 17 | $if field.indirections > 0 { |
| 18 | assert field.indirections == 1 |
| 19 | return 'a' |
| 20 | } $else { |
| 21 | return 'b' |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | return 'z' |
| 26 | } |
| 27 | |
| 28 | fn test_check() { |
| 29 | e := Encoder{} |
| 30 | mut sb := Writer{} |
| 31 | |
| 32 | mut string_initialized_with_reference := 'ads' |
| 33 | e.encode_value(StructTypePointer[string]{ val: &string_initialized_with_reference }, mut sb) or {} |
| 34 | } |
| 35 | |