Skip to content

Commit

Permalink
Merge pull request #3492 from 9rnsr/fix12554
Browse files Browse the repository at this point in the history
[REG2.066a] Issue 12554 - [ICE](struct.c line 898) with failed delegate purity
  • Loading branch information
WalterBright committed Apr 24, 2014
2 parents e3afe41 + a3a203f commit 215ef5e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/class.c
Expand Up @@ -266,7 +266,7 @@ void ClassDeclaration::semantic(Scope *sc)
if (type->ty == Tclass && ((TypeClass *)type)->sym != this)
{
TemplateInstance *ti = ((TypeClass *)type)->sym->isInstantiated();
if (ti && ti->errors)
if (ti && isError(ti))
((TypeClass *)type)->sym = this;
}

Expand Down Expand Up @@ -1268,7 +1268,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
if (type->ty == Tclass && ((TypeClass *)type)->sym != this)
{
TemplateInstance *ti = ((TypeClass *)type)->sym->isInstantiated();
if (ti && ti->errors)
if (ti && isError(ti))
((TypeClass *)type)->sym = this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/struct.c
Expand Up @@ -691,7 +691,7 @@ void StructDeclaration::semantic(Scope *sc)
if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this)
{
TemplateInstance *ti = ((TypeStruct *)type)->sym->isInstantiated();
if (ti && ti->errors)
if (ti && isError(ti))
((TypeStruct *)type)->sym = this;
}

Expand Down
55 changes: 55 additions & 0 deletions test/fail_compilation/ice12554.d
@@ -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);
}
}

0 comments on commit 215ef5e

Please sign in to comment.