[Issue 16056] immutable delegate can mutate through context pointer

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 22 07:29:20 PDT 2016


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

--- Comment #2 from Eyal Lotem <eyal.lotem at gmail.com> ---
(In reply to ag0aep6g from comment #1)
> The struct doesn't really matter here, as far as I see. Simplified code:
> 
> ----
> import std.stdio;
> 
> pure void pure_func(immutable void delegate() pure f)
> {
>     f();
> }
> 
> void main() {
>     int y;
>     writeln("Before: ", y);
>     pure_func({ y++; });
>     writeln("After: ", y);
> }
> ----
> 
> Possibly a duplicate of issue 11043 or issue 1983.

This is simpler -- but this simpler example isn't a bug: a pure func that takes
a mutable delegate is "weakly pure" because it doesn't take an immutable
argument. You could say that the simplified pure func takes an explicitly
mutable argument, so it is known to be weakly pure.

When you do take an immutable argument in a pure function -- the immutability
is supposed to be transitive -- so it is supposed to be strongly pure.

--


More information about the Digitalmars-d-bugs mailing list