Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3426 from 9rnsr/fix12174
[REG2.064] Issue 12174 - Problems caused by enum predicate with std.algorithm.sum
- Loading branch information
Showing
3 changed files
with
114 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/ice12174.d(12): Error: no property 'sum' for type 'int[]' | ||
fail_compilation/ice12174.d(20): Error: CTFE failed because of previous errors in this | ||
fail_compilation/ice12174.d(13): called from here: filter([1, 2, 3]) | ||
--- | ||
*/ | ||
|
||
void main() | ||
{ | ||
enum foo3 = (int n) => [1,2,3].sum; | ||
enum bar3 = [1,2,3].filter!(n => n % foo3(n) == 0); | ||
} | ||
|
||
template filter(alias pred) | ||
{ | ||
auto filter(Range)(Range rs) | ||
{ | ||
return FilterResult!(pred, Range)(rs); | ||
} | ||
} | ||
|
||
private struct FilterResult(alias pred, R) | ||
{ | ||
R _input; | ||
|
||
this(R r) | ||
{ | ||
_input = r; | ||
while (_input.length && !pred(_input[0])) | ||
{ | ||
_input = _input[1..$]; | ||
} | ||
} | ||
|
||
@property bool empty() { return _input.length == 0; } | ||
|
||
@property auto ref front() | ||
{ | ||
return _input[0]; | ||
} | ||
|
||
void popFront() | ||
{ | ||
do | ||
{ | ||
_input = _input[1..$]; | ||
} while (_input.length && !pred(_input[0])); | ||
} | ||
} |