Bug 17335 – Function calls in conjunctions do not short circuit when evaluated during compilation
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-04-20T16:48:00Z
Last change time
2017-08-07T13:15:47Z
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2017-04-20T16:48:30Z
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.