D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17335 - Function calls in conjunctions do not short circuit when evaluated during compilation
Summary: Function calls in conjunctions do not short circuit when evaluated during com...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 blocker
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-20 16:48 UTC by Andrei Alexandrescu
Modified: 2017-08-07 13:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2017-04-20 16:48:30 UTC
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 Andrei Alexandrescu 2017-04-20 16:48:51 UTC
Related: https://issues.dlang.org/show_bug.cgi?id=17334
Comment 2 Walter Bright 2017-04-20 18:40:18 UTC
Thanks for the succinct test case. I think I know what is wrong, I'll work on fixing it.
Comment 3 Walter Bright 2017-04-21 02:59:43 UTC
https://github.com/dlang/dmd/pull/6713
Comment 4 github-bugzilla 2017-04-21 19:36:20 UTC
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 github-bugzilla 2017-06-17 11:33:57 UTC
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 github-bugzilla 2017-08-07 13:15:47 UTC
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