[Issue 15055] isArray!NonArray doesn't short-circuit an expression

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Sep 13 08:18:45 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15055

--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
This is a duplication of enhancement issue 9073.

With static if and static assert, short circuit works for the logical
expressions, like A && B - If A is evaluated to false at compile time, B won't
be evaluated *even if B is an invalid expression*.

On the other hand, an initializer expression on enum variable declaration does
not work as so. With A && B, B is evaluated *always* and will make error if
it's not correct.

In old days, I've opened a PR to fix 9073, but was rejected by Walter.
https://github.com/D-Programming-Language/dmd/pull/2559

To do what you expect, the template should be rewritten to:

template sameUnqualArrays(A, B) {
    //enum bool sameUnqualArrays = isArray!A && isArray!B &&
    //    is(Unqual!(ForeachType!A) == Unqual!(ForeachType!B));
    static if (isArray!A && isArray!B &&
               is(Unqual!(ForeachType!A) == Unqual!(ForeachType!B)))
    {
        enum bool sameUnqualArrays = true;
    }
    else
        enum bool sameUnqualArrays = false;
}

--


More information about the Digitalmars-d-bugs mailing list