https://issues.dlang.org/show_bug.cgi?id=22010
Mathias LANG <pro.mathias.l...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pro.mathias.l...@gmail.com --- Comment #4 from Mathias LANG <pro.mathias.l...@gmail.com> --- I believe I hit this issue as well. The key seems to be the mutual recursion. In my case, the code is the following: ``` import std.sumtype; import std.stdio; alias ST = SumType!(int, long, Custom[]); struct Custom { int a; ST b; } void main () { const SumType!(int, long, Custom[]) st = [ Custom(42), Custom(69) ]; version(all) writeln(st); assert(st.toString() == "NULL"); } ``` With this, I get a compiler error: ``` /usr/include/dmd/phobos/std/sumtype.d(1945): Error: need `this` for `tags` of type `ulong[1]` Error: `this` for `__invariant1322` needs to be type `TagTuple` not type `const(TagTuple)` /usr/include/dmd/phobos/std/sumtype.d(2102): Error: static assert: "No matching handler for types `(const(Custom[]))`" /usr/include/dmd/phobos/std/sumtype.d(1662): instantiated from here: `matchImpl!(const(SumType!(int, long, Custom[])))` /usr/include/dmd/phobos/std/sumtype.d(787): instantiated from here: `match!(const(SumType!(int, long, Custom[])))` st.d(16): instantiated from here: `toString!(const(SumType!(int, long, Custom[])))` ``` Now if you remove the `writeln` in `version(all)`, you end up with: ``` ld: error: undefined symbol: _D3std6format5write__T11formatValueTSQBj5array__T8AppenderTAyaZQoTAxS2st6CustomTaZQCiFKQBzKQzMKxSQDrQDq4spec__T10FormatSpecTaZQpZv >>> referenced by st.d >>> st.o:(_D3std4conv__T5toStrTAyaTAxS2st6CustomZQzFQrZQy) collect2: error: ld returned 1 exit status Error: linker exited with status 1 ``` Looking at SumType's code, it seems the instantiation of `formatValue` happens here: https://github.com/dlang/phobos/blob/dba1bbe271a9b2d7f24edeebbc77846e29904e41/std/sumtype.d#L807 --