www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17335] New: Function calls in conjunctions do not short

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

          Issue ID: 17335
           Summary: Function calls in conjunctions do not short circuit
                    when evaluated during compilation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

Consider:

bool alwaysFalse() { return false; }
void main()
{
    static if (false && a == 1)
    {
    }
    static if ("a" == "b" && b == 1)
    {
    }
    static if (alwaysFalse() && c == 1)
    {
    }
}

The first static if passes, even though the name `a` is not defined. This is
because the `false` constant short circuits the conjunction. The second static
if also passes because of special code in comparison that evaluates it
statically if needed, and again the false result short circuits the
conjunction.

The third static if does not pass because there is no attempt to evaluate the
function during compilation (even though obviously it is computable during
compilation).

This blocks Lucia's work on lowering array comparisons. Fixing this bug would
not only make that work, but would improve a host of other cases.

--
Apr 20 2017