On Wednesday, 10 May 2017 at 09:42:53 UTC, Timon Gehr wrote:
On 09.05.2017 23:56, Timon Gehr wrote:

core.exception.AssertError@ddmd/blockexit.d(90): Assertion failure
----------------
...

Thanks! (It's a known issue though:
https://github.com/tgehr/dmd/blob/static-foreach/test_staticforeach.d#L330.)


Actually, yours is a different case with the same outcome (f and idonotexist do not matter at all, the issue exists even for static foreach(j;0..0){}). All static foreach loops over empty (non-AliasSeq) aggregates failed that assertion. The reason was that CTFE can return a null literal from a function that returns T[], but the constant folder cannot actually evaluate null.length for some reason.

So here is the difference between null and []:

null :

() { Slice* s; s = null; return s; }

[] :
() { Slice* s; s = alloca(sizeof(*s)); s.base = null; s.length = 0; return s; }

Therefore

null.length => (cast(Slice*)null).length; which results in a segfault.

and

[].length => (cast(Slice*)somevalidSliceDiscriptor).length;

Reply via email to