From de7df6bfeb5cc61f18c4730a2e129d7783e6b68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 7 Dec 2017 20:41:06 +0100 Subject: [PATCH] Fix hasType!T when called with rvalues. --- source/taggedalgebraic.d | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/taggedalgebraic.d b/source/taggedalgebraic.d index 7b0e42a..37d7792 100644 --- a/source/taggedalgebraic.d +++ b/source/taggedalgebraic.d @@ -611,6 +611,11 @@ bool hasType(T, U)(in ref TaggedAlgebraic!U ta) } assert(false); // never reached } +/// ditto +bool hasType(T, U)(in TaggedAlgebraic!U ta) +{ + return hasType!(T, U)(ta); +} /// unittest { @@ -641,6 +646,18 @@ unittest { // issue #1 assert(ta.hasType!int); } +unittest { + union U { + int a; + float b; + } + alias TA = TaggedAlgebraic!U; + + const(TA) test() { return TA(12); } + assert(test().hasType!int); +} + + /** Gets the value stored in an algebraic type based on its data type. */ ref inout(T) get(T, U)(ref inout(TaggedAlgebraic!U) ta)