[Issue 17473] New: foreach on delegates incorrectly rejected

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 6 15:43:12 PDT 2017


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

          Issue ID: 17473
           Summary: foreach on delegates incorrectly rejected
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

Here is an incorrect rejection of a valid program:

struct S {
    int f(int delegate(char a) dlg) {
        char c = cast(char)50;
        return dlg(c);
    }
}

unittest {
    S s;
    pragma(msg, typeof(&s.f));  // int delegate(int delegate(char a) dlg)
    foreach(x; &s.f) {}

    int delegate(int delegate(char a) dlg) g = &s.f;
    pragma(msg, typeof(g));     // int delegate(int delegate(char a) dlg)
    foreach(x; g) {}            // FAILS
}

--


More information about the Digitalmars-d-bugs mailing list