struct Range { size_t front() { return 0; } void popFront() { empty = true; } bool empty; } struct ARange { Range range; alias range this; } void main() { ARange arange; assert(arange.front == 0); foreach(e; arange) {} } --- Foreach creates a reference to arange. The expression that initializes the reference is dropped for alias this aggregates. This is a regression introduced by https://github.com/D-Programming-Language/dmd/commit/6a2aefdb468d20aa8d498c8930c2613d78a91238 as a fix to #2781.
Your patch was already merged (commit: f53ff46), and it looks correct to me the fixing lack of merging prelude before semantic. But, your sample code works before merging (commit: 07f719e), so that code is not test case of this issue. Do you have right test case?
https://github.com/D-Programming-Language/dmd/commit/fed2faabc3ca9f67a429293eee82ae597061fea8
(In reply to comment #1) > Your patch was already merged (commit: f53ff46), and it looks correct to me the > fixing lack of merging prelude before semantic. > > But, your sample code works before merging (commit: 07f719e), so that code is > not test case of this issue. > > Do you have right test case? This is probably due to constant folding or optimization. The merged version has 'assert(e == 0);' in the loop body.