Skip to content

Commit

Permalink
Merge pull request #2289 from 9rnsr/fix10506
Browse files Browse the repository at this point in the history
Issue 10506 - Purity should not be checked in a mixin statement
  • Loading branch information
WalterBright committed Jul 5, 2013
2 parents 11d22d6 + 075f1ec commit d16ce29
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ void Expression::checkPurity(Scope *sc, FuncDeclaration *f)
f->parent->isTemplateInstance()->enclosing == NULL)
{ // The closest pure parent of instantiated non-nested template function is
// always itself.
if (!f->isPure() && outerfunc->setImpure())
if (!f->isPure() && outerfunc->setImpure() && !sc->needctfe)
error("pure function '%s' cannot call impure function '%s'",
outerfunc->toPrettyChars(), f->toPrettyChars());
return;
Expand Down
6 changes: 4 additions & 2 deletions src/traits.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,10 @@ Expression *TraitsExp::semantic(Scope *sc)
unsigned errors = global.startGagging();
unsigned oldspec = global.speculativeGag;
global.speculativeGag = global.gag;
bool scSpec = sc->speculative;
sc = sc->push();
sc->speculative = true;
sc->needctfe = 0;
sc->flags = sc->enclosing->flags; // inherit

Type *t = isType(o);
if (t)
Expand All @@ -606,7 +608,7 @@ Expression *TraitsExp::semantic(Scope *sc)
}
}

sc->speculative = scSpec;
sc = sc->pop();
global.speculativeGag = oldspec;
if (global.endGagging(errors))
{
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,23 @@ void test6169() pure @safe
enum z = ctfefptr6169();
}

/***************************************************/
// 10506

void impureFunc10506() {}
string join10506(RoR)(RoR ror)
{
impureFunc10506();
return ror[0] ~ ror[1];
}

void test10506() pure
{
void foobar() {}

mixin(["foo", "bar"].join10506()~";");
}

/***************************************************/

const shared class C5107
Expand Down

0 comments on commit d16ce29

Please sign in to comment.