From 9b13f08a25e6ef63fcdb4b3a789defb978a1e63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 18 Jan 2018 00:29:16 +0100 Subject: [PATCH] Fix compile error for overloaded TaggedAlgebraic returns. Fixes #13. --- source/taggedalgebraic.d | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source/taggedalgebraic.d b/source/taggedalgebraic.d index 75c0197..ee0ea77 100644 --- a/source/taggedalgebraic.d +++ b/source/taggedalgebraic.d @@ -595,6 +595,22 @@ unittest } } +unittest { // issue #13 + struct S1 { int foo; } + struct S { + struct T { TaggedAlgebraic!S1 foo() { return TaggedAlgebraic!S1(42); } } + struct U { string foo() { return "foo"; } } + T t; + U u; + } + alias TA = TaggedAlgebraic!S; + auto ta = TA(S.T.init); + assert(ta.foo().get!(TaggedAlgebraic!S1) == 42); + + ta = TA(S.U.init); + assert(ta.foo() == "foo"); +} + /** Tests if the algebraic type stores a value of a certain data type. */ @@ -867,8 +883,7 @@ private static auto implementOp(OpKind kind, string name, T, ARGS...)(ref T self alias Alg = Algebraic!(NoDuplicates!(info.ReturnTypes)); info.ReturnTypes[i] ret = info.perform(self.trustedGet!FT, args); import std.traits : isInstanceOf; - static if (isInstanceOf!(TaggedAlgebraic, typeof(ret))) return Alg(ret.payload); - else return Alg(ret); + return Alg(ret); } else static if (is(FT == Variant)) return info.perform(self.trustedGet!FT, args);