Thread overview
[Issue 23136] closure in a loop should hold distinct values for each iteration
Jun 14
JR
5 days ago
Bolpat
May 24
https://issues.dlang.org/show_bug.cgi?id=23136

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--
May 24
https://issues.dlang.org/show_bug.cgi?id=23136

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=2043

--
June 14
https://issues.dlang.org/show_bug.cgi?id=23136

JR <zorael@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zorael@gmail.com

--
5 days ago
https://issues.dlang.org/show_bug.cgi?id=23136

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--- Comment #1 from Bolpat <qs.il.paperinik@gmail.com> ---
To be honest, I find this worse:

```d
import std.stdio;

void main() @safe
{
    int delegate() immutable pure @safe[] dgList;
    foreach(int i; [0,1,2])
    {
        immutable b = i;
        dgList ~= () immutable pure @safe => b;
        writeln(dgList[$-1]());
    }
    writeln;
    foreach(dg; dgList) writeln(dg());
}
```

An immutable pure @safe delegate should never ever be able to return different values for the same parameters (in particular: no parameters).

--