[Issue 9724] New: Range predicates are not restrictive enough to justify assumptions made in Phobos code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 14 15:22:17 PDT 2013


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

           Summary: Range predicates are not restrictive enough to justify
                    assumptions made in Phobos code
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: timon.gehr at gmx.ch


--- Comment #0 from timon.gehr at gmx.ch 2013-03-14 15:22:16 PDT ---
DMD/Phobos 2.062:

Eg. the following breaks most of std.range, and most of std.algorithm could
likely be broken too, but I am too lazy to investigate.

import std.range, std.algorithm;

struct TrollFace{
    @property string front()const{ return "troll"; }
    @property string back()const{ return "face"; }
    @property bool empty()const{ return true; }
    void popFront()const{ }
    void popBack()const{ }
    @property inout(TrollFace) save()inout{ return this; }
    auto opIndex(size_t index){ return front; }
    @property size_t length()inout{ return 0; }
    int* x;
}
struct TrollierFace{
    TrollFace face;
    alias face this;
    @disable this(this);
    @property inout(TrollierFace) save()inout{ return
inout(TrollierFace)(face); }
}

void main(){
    immutable TrollFace a,b,c;
    a.retro();
    a.stride(2);
    chain(a,b,c);
    roundRobin(a,b,c);
    a.radial();
    a.radial(0);
    a.take(2);
    (immutable(TrollierFace)()).takeExactly(2);
    (immutable(TrollierFace)()).takeOne();
    (immutable(TrollierFace)()).takeNone();
    (immutable(TrollierFace)()).drop(2);
    (immutable(TrollierFace)()).dropExactly(0);
    (immutable(TrollierFace)()).dropOne();
    (immutable(TrollierFace)()).repeat();
    a.cycle();
    a.zip(b);
    lockstep((immutable(TrollierFace)()),b);
    a.frontTransversal();
    a.transversal(0);
    a.indexed([0]);
    a.chunks(5);
    a.filter!(a=>true);
    a.map!(a=>a);
    // ... (and so on)
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list