[Issue 8625] New: foreach doesn't do implicit conversions on associative arrays and opApply

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 5 20:41:17 PDT 2012


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

           Summary: foreach doesn't do implicit conversions on associative
                    arrays and opApply
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: nilsbossung at googlemail.com


--- Comment #0 from Nils <nilsbossung at googlemail.com> 2012-09-05 20:41:43 PDT ---
This should compile:

void main() {
    int[int] aa;
    foreach(long k, long v; aa) {} // fails on both k and v
        // test.d(3): Error: foreach: index must be type int, not long
        // test.d(3): Error: foreach: value must be type int, not long

    static struct OpApply {
        int opApply(int delegate(int)) {return 0;}
    }
    foreach(long x; OpApply()) {} // fails
        // test.d(10): Error: cannot uniquely infer foreach argument types

    // In contrast, it does work on plain arrays and ranges:

    int[] a;
    foreach(long x; a) {} // ok

    static struct Range {
        @property bool empty() {return false;}
        @property int front() {return 0;}
        void popFront() {}
    }
    foreach(long x; Range()) {} // ok
}

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