The following code should print 2 but writes random numbers instead: void main() @safe { import std.stdio : writeln; writeln(identity(2)); } int identity(immutable int q) pure nothrow @safe @nogc { import std.algorithm : map; static immutable auto arr = [42]; int getSecondArgument(int a, int b) { return b; } return arr.map!((int a, int b = q) => getSecondArgument(a, b))[0]; }
Reduced Phobos away: ---- void main() @safe { assert(identity(2) == 2); /* fails; should pass */ } struct Map(alias fun) { int front() @safe { return fun(); } } int identity(immutable int q) pure nothrow @safe @nogc { int getArg(int b) @safe { return b; } return Map!((int b = q) => getArg(b))().front(); } ----
This should fail to compile, and in this case you can use `lazy int b = q` and will work.
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19440 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB