Bug 4218 – safe function cannot call opApply

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-05-21T10:33:00Z
Last change time
2014-02-15T02:43:25Z
Assigned to
nobody
Creator
zan77137

Comments

Comment #0 by zan77137 — 2010-05-21T10:33:41Z
This code doesn't work! -------------------------------------------- struct S{ @safe int opApply(scope int delegate(ref int) dg){return 0;} } @safe void main() { S s; foreach (x; s) {} } -------------------------------------------- @safe delegate can implicit convert to @system delegate. Following code can compile: -------------------------------------------- struct S{ @safe void foo(){} } @safe void main() { S s; void delegate() dg = &s.foo; } -------------------------------------------- And of course, "int delegate(ref int) @safe" should convert to "int delegate(ref int)". Therefore, safe function should allow to call opApply. Workaround is here: -------------------------------------------- struct S{ @safe int opApply(scope int delegate(ref int) dg){return 0;} @safe int opApply(scope int delegate(ref int)@safe dg){return 0;} } @safe void foo() { S s; foreach (x; s) {} } @system void main() { S s; foreach (x; s) {} foo(); } --------------------------------------------
Comment #1 by yebblies — 2011-06-13T12:16:14Z
The underlying issue a dupe of bug 3180. *** This issue has been marked as a duplicate of issue 3180 ***