[Issue 15624] New: opApply with @safe and @system variants can't be used with foreach syntax
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jan 29 12:16:05 PST 2016
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 at puremagic.com
Reporter: dhasenan at 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.
--
More information about the Digitalmars-d-bugs
mailing list