[Issue 17335] New: Function calls in conjunctions do not short circuit when evaluated during compilation
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Apr 20 09:48:30 PDT 2017
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 at puremagic.com
Reporter: andrei at 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.
--
More information about the Digitalmars-d-bugs
mailing list