import std.variant; import std.meta: AliasSeq; alias Inner = Algebraic!(This*); alias Outer = Algebraic!(Inner, This*); static assert(is(Outer.AllowedTypes == AliasSeq!(Inner, Outer*))); --- $ dmd -c example.d /usr/include/dmd/phobos/std/typecons.d(8730): Error: template instance `std.typecons.ReplaceType!(This, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, U!(8LU, VariantN!(16LU, VariantN!(8LU, This*), This*)*)*)*)*)*)*)*)*)*)*)*)*)*), U!(8LU, VariantN!(16LU, VariantN!(8LU, This*), This*)*)*)` recursive expansion To avoid this error, Algebraic should not attempt to replace occurrences of This that appear inside other instances of Algebraic.
@pbackus created dlang/phobos pull request #7084 "Fix issue 19994 - Can't nest self-referential Algebraic types" fixing this issue: - Fix issue 19994 - Can't nest self-referential Algebraic types https://github.com/dlang/phobos/pull/7084
dlang/phobos pull request #7084 "Fix issue 19994 - Can't nest self-referential Algebraic types" was merged into master: - 8124b17e2c24e1b67cb7a40dcb80f460ef6825f1 by Paul Backus: Fix issue 19994 - Can't nest self-referential Algebraic types https://github.com/dlang/phobos/pull/7084