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.
Related: https://issues.dlang.org/show_bug.cgi?id=17334
Thanks for the succinct test case. I think I know what is wrong, I'll work on fixing it.
https://github.com/dlang/dmd/pull/6713
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…
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
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