[Issue 6230] Member functions can no longer be weakly pure
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 30 09:55:10 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6230
--- Comment #1 from kennytm at gmail.com 2011-06-30 09:50:12 PDT ---
One possible patch:
diff --git a/src/expression.c b/src/expression.c
index 57cdd61..71f6239 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -1366,17 +1366,23 @@ void Expression::checkPurity(Scope *sc, VarDeclaration
*v, Expression *ethis)
* requiring each function in between to be impure.
*/
Dsymbol *vparent = v->toParent2();
- for (Dsymbol *s = sc->func; s; s = s->toParent2())
+ Dsymbol *s = sc->func, *snext = s->toParent2();
+ // Make sure we're really finding parent *functions*, not parent
+ // class.
+ if (vparent->isFuncDeclaration() || snext != vparent)
{
- if (s == vparent)
- break;
- FuncDeclaration *ff = s->isFuncDeclaration();
- if (!ff)
- break;
- if (ff->setImpure())
- { error("pure nested function '%s' cannot access mutable
data '%s'",
- ff->toChars(), v->toChars());
- break;
+ for (; s; s = s->toParent2())
+ {
+ if (s == vparent)
+ break;
+ FuncDeclaration *ff = s->isFuncDeclaration();
+ if (!ff)
+ break;
+ if (ff->setImpure())
+ { error("pure nested function '%s' cannot access mutable
data '%s'",
+ ff->toChars(), v->toChars());
+ break;
+ }
}
}
}
diff --git a/src/func.c b/src/func.c
index 9957d7f..1cccbed 100644
--- a/src/func.c
+++ b/src/func.c
@@ -2664,9 +2664,9 @@ enum PURE FuncDeclaration::isPure()
TypeFunction *tf = (TypeFunction *)type;
if (flags & FUNCFLAGpurityInprocess)
setImpure();
- enum PURE purity = tf->purity;
- if (purity == PUREfwdref)
+ if (tf->purity == PUREfwdref)
tf->purityLevel();
+ enum PURE purity = tf->purity;
if (purity > PUREweak && needThis())
{ // The attribute of the 'this' reference affects purity strength
if (type->mod & (MODimmutable | MODwild))
@@ -2676,6 +2676,9 @@ enum PURE FuncDeclaration::isPure()
else
purity = PUREweak;
}
+ tf->purity = purity;
+ // ^ This rely on the current situation that every FuncDeclaration has a
+ // unique TypeFunction.
return purity;
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list