[Issue 18909] New: Lambda with default initializer gets called with random values instead

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 26 16:12:25 UTC 2018


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: nobody at puremagic.com
          Reporter: Malwas3 at aol.com

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];
}

--


More information about the Digitalmars-d-bugs mailing list