[Issue 17645] `pure` is transitively applied to all delegates inside a pure function

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 17 09:39:46 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17645

--- Comment #5 from Tomer Filiba (weka) <tomer at weka.io> ---
(In reply to Steven Schveighoffer from comment #4)
> `format` actually is pure.

nitpicking. sure, format may be pure, but the variables i want to log in the
assert may be __gshared and then i can't access them. or i may want to invoke
some impure functions to add extra info before the process dies. e.g.

assert (cond, "%s x=%s".format(getTimeOfDay(), x));

> In your new example, you are actually calling the
> GC-allocating function from inside a @nogc context, not creating a delegate.
> Even if you did create a delegate and needed to save the context, that
> creates a closure, and that definitely needs the GC.

the ASSERT function takes a `scope delegate` so no closure of GC is needed.
unless it blows up, and then i'm ok with that.

> So you have a few choices here:
> 
> 1. Update the bug to say that these should be inferred as functions (even if
> you don't do this, another bug should be filed).
> 2. Argue that a delegate with a context of a pure function should be able to
> be unpure, and demonstrate why that's needed with an updated use case.
> 3. Alter the bug report to mean something different.

opting for 2. i will file another bug for the inference issue, but i don't see
why this is not a bug. the fact i *create* a delegate in a pure scope shouldn't
force the *delegate* to be pure. i shouldn't be able to *invoke* that impure
delegate, just like i shouldn't be able to invoke any other impure function.
but that's not the issue. once i have a delegate, i just cast it to a pure one
-- and this will happen only when the assert blows up.

and the function(){} hack won't help me, because i require access to
arguments/variables on the function's stack.

--


More information about the Digitalmars-d-bugs mailing list