sumtype icon indicating copy to clipboard operation
sumtype copied to clipboard

SumType fails to replace This[] inside Tuple!()

Open DolphinChips opened this issue 4 years ago • 1 comments

Using sumtype 1.1.1:

import std.typecons : Tuple;
import sumtype;

alias A = SumType!(Tuple!(This[]));

void main() {}

fails with:

.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(281,16): Error: template instance `AliasSeq!(ReplaceTypeUnless!(isSumTypeInstance, This, SumType!(Tuple!(This[])), Tuple!(This[])))` recursive template expansion
/dlang/dmd/linux/bin64/../../src/phobos/std/typecons.d(9037,39): Error: template instance `std.typecons.U!(SumType!(Tuple!(This[]))[])` error instantiating
.dub/packages/sumtype-1.1.1/sumtype/src/sumtype.d(282,3):        instantiated from here: `ReplaceTypeUnless!(isSumTypeInstance, This, SumType!(Tuple!(This[])), Tuple!(This[]))`
onlineapp.d(7,11):        instantiated from here: `SumType!(Tuple!(This[]))`
dmd failed with exit code 1.

Link to run.dlang.io: https://run.dlang.io/is/Vm8AAK

Same code but with This[] outside of Tuple!() works fine

DolphinChips avatar May 01 '21 16:05 DolphinChips

The example compiles successfully if you replace std.typecons.Tuple with the following simplified version:

struct Tuple(Types...)
{
    Types expand;
}

(run.dlang.io link: https://run.dlang.io/is/avNK7w)

So, something in the implementation of std.typecons.Tuple must be creating a circular dependency. I'm not sure there's anything SumType can do about this, but I'll investigate anyway, since there may be a way to work around it in Tuple.

pbackus avatar May 01 '21 19:05 pbackus