www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4291] New: Pure functions cannot access mixed in variables

reply d-bugmail puremagic.com writes:
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


--- Comment #0 from Shin Fujishiro <rsinfu gmail.com> 2010-06-07 02:40:13 PDT
---
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4291


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-06-07 02:41:25 PDT
---
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
prev sibling parent d-bugmail puremagic.com writes:
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


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2010-08-28
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