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 #3492 from 9rnsr/fix12554
[REG2.066a] Issue 12554 - [ICE](struct.c line 898) with failed delegate purity
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 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,55 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/ice12554.d(18): Error: pure function 'D main' cannot call impure function 'ice12554.array!(MapResult!((y) => x)).array' | ||
fail_compilation/ice12554.d(37): instantiated from here: MapResult!((x) => foo.map!(MapResultS, (y) => x).array) | ||
fail_compilation/ice12554.d(18): instantiated from here: map!(int[]) | ||
fail_compilation/ice12554.d(21): Error: pure function 'D main' cannot call impure function 'ice12554.array!(MapResult!((y) => x)).array' | ||
fail_compilation/ice12554.d(37): instantiated from here: MapResult!((x) => foo.map!(MapResultC, (y) => x).array) | ||
fail_compilation/ice12554.d(21): instantiated from here: map!(int[]) | ||
--- | ||
*/ | ||
|
||
void main() pure | ||
{ | ||
int[] foo; | ||
|
||
// if indirectly instantiated aggregate is struct (== MapResultS) | ||
foo.map!(MapResultS, x => foo.map!(MapResultS, y => x).array); | ||
|
||
// if indirectly instantiated aggregate is class (== MapResultC) | ||
foo.map!(MapResultC, x => foo.map!(MapResultC, y => x).array); | ||
} | ||
|
||
T array(T)(T a) | ||
{ | ||
static int g; g = 1; // impure operation | ||
return a; | ||
} | ||
|
||
template map(alias MapResult, fun...) | ||
{ | ||
auto map(Range)(Range r) | ||
{ | ||
alias AppliedReturnType(alias f) = typeof(f(r[0])); | ||
static assert(!is(AppliedReturnType!fun == void)); | ||
|
||
return MapResult!(fun).init; | ||
} | ||
} | ||
|
||
struct MapResultS(alias fun) | ||
{ | ||
@property front() | ||
{ | ||
return fun(1); | ||
} | ||
} | ||
|
||
class MapResultC(alias fun) | ||
{ | ||
@property front() | ||
{ | ||
return fun(1); | ||
} | ||
} |