http://d.puremagic.com/issues/show_bug.cgi?id=2601

           Summary: Extraneous cast introduced in member access
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzi...@digitalmars.com
        ReportedBy: and...@metalanguage.com


I could probably simplify this a bit more, but it's short enough:

import std.functional;

void next(T)(ref T[] a) { assert(a.length); a = a[1 .. $]; }

struct MapRange(alias funAlias, Range)
{
    Range _input;
    void next() { _input.next; }
}

template map(fun...)
{
    alias mapImpl!(fun).result map;
}

template mapImpl(alias fun)
{
    MapRange!(fun, Range) result(Range)(Range input)
    {
        return typeof(return)(input);
    }
}

unittest
{
    auto x = map!("2 * a")([1, 2, 3, 4, 5]);
    //auto y = mapImpl!(fun).result!("2 * a")([1, 2, 3, 4, 5]);
}

The code fails to compile with:

Error: cast(int[])this._input is not an lvalue

As a bonus, uncommenting the last (albeit incorrect) line in unittest crashes
dmd.


-- 

Reply via email to