Summary: Allow pure functions to have lazy arguments
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Don <> 2011-03-18 17:34:21 PDT ---
Any function marked as pure, which has a lazy parameter, should be considered
to be weakly pure. Since a lazy parameter is a delegate, there are no limits on
what it can potentially do, so the purity of the function will depend entirely
on the purity of the lazy parameter.

Secondly, when using a lazy parameter, it should be assumed to be adequately
pure, since it was checked when it was constructed.

mtype.c, line 5042, void TypeFunction::purityLevel()

            size_t dim = Parameter::dim(tf->parameters);
            for (size_t i = 0; i < dim; i++)
            {   Parameter *fparam = Parameter::getNth(tf->parameters, i);
                if (fparam->storageClass & STClazy)
-                    /* We could possibly allow this by doing further analysis
on the
-                     * lazy parameter to see if it's pure.
-                     */
-                    error(0, "cannot have lazy parameters to a pure
+                    tf->purity = PUREweak;
+                    break;
                if (fparam->storageClass & STCout)

expression.c, line 7155, CallExp::semantic()
            if (sc->func && sc->func->isPure() && !tf->purity)
+                if (e1->op == TOKvar && ((VarExp *)e1)->var->storage_class &
+                {   // lazy paramaters can be called without violating purity
+                    // since they are checked explicitly
+                }
+                else
                error("pure function '%s' cannot call impure delegate '%s'",
sc->func->toChars(), e1->toChars());
            if (sc->func && sc->func->isSafe() && tf->trust <= TRUSTsystem)
                error("safe function '%s' cannot call system delegate '%s'",
sc->func->toChars(), e1->toChars());

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to