[Issue 14306] Wrong codegen with -inline for generic lambdas

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Mar 18 14:50:14 PDT 2015


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

--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
Test case without imports:
---------
template map(alias fun)
{
    auto map(Range)(Range r)
    {
        return MapResult!(fun, Range)(r);
    }
}

struct MapResult(alias fun, Range)
{
    alias R = Range;
    R _input;

    this(R input)
    {
        _input = input;
    }

    @property bool empty()
    {
    return _input.empty;
    }

    void popFront()
    {
        _input.popFront();
    }

    @property auto ref front()
    {
        return fun(_input.front);
    }
}


auto iota(int end)
{
    static struct Result
    {
    int end = 100;
    int i = 0;
    @property bool empty() { return i == end; }
    @property int front() { return i; }
    void popFront() { ++i; }
    }
    return Result();
}

void bar(R)(R r)
{
    foreach (x; r) { }
}

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

void fun(ref S s) {
    iota(100).map!(x => s.bump()).bar;
//    iota(100).map!((int x) => s.bump()).bar;
    assert(s.x == 100);
}

void main() {
    S s;
    fun(s);
}

--


More information about the Digitalmars-d-bugs mailing list