From 3709a2298f0b429b67c8be81b0ded79623560b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 18 Jan 2018 00:31:00 +0100 Subject: [PATCH] Add test and close #8. Was fixed by 513729bf59b1d10561ceb132d1e6ce5d9dba423e for compiler frontend versions >= 2.072.x. --- source/taggedalgebraic.d | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source/taggedalgebraic.d b/source/taggedalgebraic.d index ee0ea77..36be689 100644 --- a/source/taggedalgebraic.d +++ b/source/taggedalgebraic.d @@ -595,6 +595,47 @@ unittest } } +static if (__VERSION__ >= 2072) { + unittest { // issue #8 + static struct Result(T,E) + { + static union U + { + T ok; + E err; + } + alias TA = TaggedAlgebraic!U; + TA payload; + alias payload this; + + this(T ok) { payload = ok; } + this(E err) { payload = err; } + } + + static struct Option(T) + { + static union U + { + T some; + typeof(null) none; + } + alias TA = TaggedAlgebraic!U; + TA payload; + alias payload this; + + this(T some) { payload = some; } + this(typeof(null) none) { payload = null; } + } + + Result!(Option!size_t, int) foo() + { + return Result!(Option!size_t, int)(42); + } + + assert(foo() == 42); + } +} + unittest { // issue #13 struct S1 { int foo; } struct S {