www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14306] New: Wrong codegen with -inline for generic lambdas

https://issues.dlang.org/show_bug.cgi?id=14306

          Issue ID: 14306
           Summary: Wrong codegen with -inline for generic lambdas
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

Consider:

import std.algorithm, std.range;

struct S {
    int x;
    int bump() { ++x; return x; }
}

int[] fun(ref S s) {
    auto a = iota(100).map!(x => s.bump).array;
    return a;
}

void main() {
    S s;
    auto a = fun(s);
    assert(s.x == 100);
}

If built without -inline, the code works. Adding -inline makes the assertion
fail (s.x is 0).

Changing the lambda from x => s.bump to (int x) => s.bump makes the code work,
so this is an issue with inlining generic lambdas.

--
Mar 18 2015