https://issues.dlang.org/show_bug.cgi?id=18909
Issue ID: 18909
Summary: Lambda with default initializer gets called with
random values instead
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
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];
}
--