From 56d50fd56c86551a3a38b141a75b30eed2c5c3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 23 Feb 2019 17:19:00 +0100 Subject: [PATCH] Work around Phobos issue 19696. --- source/taggedalgebraic/taggedunion.d | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index a564d6e..bf1b080 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -378,6 +378,22 @@ unittest { // test for name clashes assert(tu.stringValue == "foo"); } +unittest { // test woraround for Phobos issue 19696 + struct T { + struct F { int num; } + alias Payload = TaggedUnion!F; + Payload payload; + alias payload this; + } + + struct U { + T t; + } + + alias TU = TaggedUnion!U; + static assert(is(TU.FieldTypes[0] == T)); +} + /** Dispatches the value contained on a `TaggedUnion` to a set of visitors. @@ -620,7 +636,12 @@ template TypeOf(alias kind) // NOTE: ReplaceType has issues with certain types, such as a class // declaration like this: class C : D!C {} // For this reason, we test first if it compiles and only then use it. - static if (is(ReplaceType!(This, U, FT))) + // It also replaces a type with the contained "alias this" type under + // certain conditions, so we make a second check to see heuristically + // if This is actually present in FT + // + // Phobos issues: 19696, 19697 + static if (is(ReplaceType!(This, U, FT)) && !is(ReplaceType!(This, void, FT))) alias TypeOf = ReplaceType!(This, U, FT); else alias TypeOf = FT; }