| 1 | // A generic struct used as the default value of an interface-typed field inside |
| 2 | // a generic wrapper must monomorphize with the wrapper's type argument, instead |
| 3 | // of leaving the type parameter unresolved (`Text_T_T`). The leftover generic |
| 4 | // variant must also not pollute the interface's auto-generated str(). |
| 5 | // See issue #27550. |
| 6 | interface Tag { |
| 7 | tag() string |
| 8 | } |
| 9 | |
| 10 | struct Text[T] { |
| 11 | val T |
| 12 | } |
| 13 | |
| 14 | fn (t Text[T]) tag() string { |
| 15 | return 'text' |
| 16 | } |
| 17 | |
| 18 | struct Wrapper[T] { |
| 19 | tag Tag = Text[T]{} |
| 20 | } |
| 21 | |
| 22 | fn test_generic_struct_default_interface_field() { |
| 23 | w := Wrapper[int]{} |
| 24 | assert w.tag.tag() == 'text' |
| 25 | // stringifying the wrapper exercises the interface variant auto-str dispatch |
| 26 | s := w.str() |
| 27 | assert s.contains('Text[int]{') |
| 28 | assert s.contains('val: 0') |
| 29 | } |
| 30 | |