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.
Comment #1 by andrei — 2017-04-20T16:48:51Z
Comment #2 by bugzilla — 2017-04-20T18:40:18Z
Thanks for the succinct test case. I think I know what is wrong, I'll work on fixing it.
Comment #3 by bugzilla — 2017-04-21T02:59:43Z
Comment #4 by github-bugzilla — 2017-04-21T19:36:20Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4d1eba7b28f8e06717252c488c4bd2b6bf2d3070 fix Issue 17335 - Function calls in conjunctions do not short circuit when evaluated during compilation https://github.com/dlang/dmd/commit/a670b6e41bcd9b04ce30e9fc70fc3f77b875f4c0 Merge pull request #6713 from WalterBright/fix17335 fix Issue 17335 - Function calls in conjunctions do not short circuit…
Comment #5 by github-bugzilla — 2017-06-17T11:33:57Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4d1eba7b28f8e06717252c488c4bd2b6bf2d3070 fix Issue 17335 - Function calls in conjunctions do not short circuit when evaluated during compilation https://github.com/dlang/dmd/commit/a670b6e41bcd9b04ce30e9fc70fc3f77b875f4c0 Merge pull request #6713 from WalterBright/fix17335
Comment #6 by github-bugzilla — 2017-08-07T13:15:47Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/4d1eba7b28f8e06717252c488c4bd2b6bf2d3070 fix Issue 17335 - Function calls in conjunctions do not short circuit when evaluated during compilation https://github.com/dlang/dmd/commit/a670b6e41bcd9b04ce30e9fc70fc3f77b875f4c0 Merge pull request #6713 from WalterBright/fix17335