From df23609f3dab4160eeb584d51405b4e3786f297a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 6 Dec 2015 14:57:30 +0100 Subject: [PATCH] Fix "statement not reachable" errors. --- source/taggedalgebraic.d | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/source/taggedalgebraic.d b/source/taggedalgebraic.d index 43fdb26..136afe5 100644 --- a/source/taggedalgebraic.d +++ b/source/taggedalgebraic.d @@ -111,16 +111,14 @@ struct TaggedAlgebraic(U) if (is(U == union) || is(U == struct)) { ~this() { - switch (m_kind) { - default: break; + final switch (m_kind) { foreach (i, tname; fieldNames) { alias T = typeof(__traits(getMember, U, tname)); - static if (hasElaborateDestructor!T) - { - case __traits(getMember, Kind, tname): + case __traits(getMember, Kind, tname): + static if (hasElaborateDestructor!T) { .destroy(trustedGet!tname); - return; - } + } + return; } } } @@ -131,13 +129,14 @@ struct TaggedAlgebraic(U) if (is(U == union) || is(U == struct)) { import std.conv : to; - switch (m_kind) { - default: assert(false, "Cannot cast a "~(cast(Kind)m_kind).to!string~" value to "~T.stringof); + final switch (m_kind) { foreach (i, FT; FieldTypes) { - static if (is(typeof(cast(T)trustedGet!(fieldNames[i])) == T)) { - case __traits(getMember, Kind, fieldNames[i]): - return cast(T)trustedGet!(fieldNames[i]); - } + case __traits(getMember, Kind, fieldNames[i]): + static if (is(typeof(trustedGet!(fieldNames[i])) : T)) { + return trustedGet!(fieldNames[i]); + } else { + assert(false, "Cannot cast a "~(cast(Kind)m_kind).to!string~" value to "~T.stringof); + } } } assert(false); // never reached