digitalmars.D.bugs - [Issue 4291] New: Pure functions cannot access mixed in variables
- d-bugmail puremagic.com (30/30) Jun 07 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4291
- d-bugmail puremagic.com (40/40) Jun 07 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4291
- d-bugmail puremagic.com (12/12) Aug 28 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4291
http://d.puremagic.com/issues/show_bug.cgi?id=4291 Summary: Pure functions cannot access mixed in variables Product: D Version: 2.041 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: rsinfu gmail.com --- DMD raises a compiler error when a mixed in variable is used in a pure function. -------------------- void test() pure { mixin declareVariable; var = 42; // Error: pure nested function 'test' cannot access // mutable data 'var' } template declareVariable() { int var; } -------------------- The mixed-in variable var should be treated as if it's directly declared in test()'s scope. So the above code should be correct and accepted. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4291 Shin Fujishiro <rsinfu gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch --- Patch against DMD r524: ==================== --- src/expression.c +++ src/expression.c -4406,7 +4406,7 Expression *VarExp::semantic(Scope *sc) error("pure function '%s' cannot access mutable static data '%s'", sc->func->toChars(), v->toChars()); } - else if (sc->func->isPure() && sc->parent != v->parent && + else if (sc->func->isPure() && sc->parent->pastMixin() != v->parent->pastMixin() && !v->isImmutable() && !(v->storage_class & STCmanifest)) { ==================== The patched code also deals with function's scope (sc->parent->pastMixin) so that this valid code is accepted: -------------------- void test() pure { mixin declareVariable; mixin declareFunction; readVar(); } template declareVariable() { int var; } template declareFunction() { int readVar() { return var; } } -------------------- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4291 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED 14:30:12 PDT --- http://www.dsource.org/projects/dmd/changeset/645 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 28 2010