www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18909] New: Lambda with default initializer gets called with


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

The following code should print 2 but writes random numbers instead:

void main()  safe
    import std.stdio : writeln;


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

May 26 2018