www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15624] New: opApply with safe and system variants can't be

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

          Issue ID: 15624
           Summary: opApply with  safe and  system variants can't be used
                    with foreach syntax
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dhasenan gmail.com

Test case:
---
struct Foo {
    int opApply(int delegate(int, string, string)  safe dg)  safe {
        return 0;
    }
    int opApply(int delegate(int, string, string)  system dg)  system {
        return 0;
    }
}
void testSafe()  safe {
    Foo foo;
    foreach (i, k, v; foo) {
    }
}
void testSystem()  system {
    Foo foo;
    foreach (i, k, v; foo) {
    }
}
void main() {
    testSafe;
    testSystem;
}
---

The compiler correctly routes things if you explicitly pass a lambda. It even
implicitly passes to the  safe variant if the lambda can be made  safe. So this
is probably something special about lowering foreach to opApply.

--
Jan 29