Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 645

Show
Ignore:
Timestamp:
08/28/10 21:29:15 (14 years ago)
Author:
walter
Message:

Issue 4291 - Pure functions cannot access mixed in variables

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/expression.c

    r640 r645  
    42694269                    hasPureParent = true; 
    42704270                    break; 
    42714271                } 
    42724272                Dsymbol *parent = outerfunc->toParent2(); 
    42734273                if (!parent) 
    42744274                    break; 
    42754275                outerfunc = parent->isFuncDeclaration(); 
    42764276            } 
    42774277 
    42784278            /* If ANY of its enclosing functions are pure, 
    42794279             * it cannot do anything impure. 
    42804280             * If it is pure, it cannot access any mutable variables other 
    42814281             * than those inside itself 
    42824282             */ 
    42834283            if (hasPureParent && v->isDataseg() && 
    42844284                !v->isImmutable()) 
    42854285            { 
    42864286                error("pure function '%s' cannot access mutable static data '%s'", 
    42874287                    sc->func->toChars(), v->toChars()); 
    42884288            } 
    4289             else if (sc->func->isPure() && sc->parent != v->parent && 
     4289            else if (sc->func->isPure() && 
     4290                sc->parent->pastMixin() != v->parent->pastMixin() && 
    42904291                !v->isImmutable() && 
    42914292                !(v->storage_class & STCmanifest)) 
    42924293            { 
    42934294                error("pure nested function '%s' cannot access mutable data '%s'", 
    42944295                    sc->func->toChars(), v->toChars()); 
    42954296                if (v->isEnumDeclaration()) 
    42964297                    error("enum"); 
    42974298            } 
    42984299 
    42994300            /* Do not allow safe functions to access __gshared data 
    43004301             */ 
    43014302            if (sc->func->isSafe() && v->storage_class & STCgshared) 
    43024303                error("safe function '%s' cannot access __gshared data '%s'", 
    43034304                    sc->func->toChars(), v->toChars()); 
    43044305        } 
    43054306#else 
    43064307        if (sc->func && sc->func->isPure() && !sc->intypeof) 
    43074308        { 
    43084309            if (v->isDataseg() && !v->isImmutable()) 
    43094310                error("pure function '%s' cannot access mutable static data '%s'", sc->func->toChars(), v->toChars());