Issue 4218 - safe function cannot call opApply
Summary: safe function cannot call opApply
Status: RESOLVED DUPLICATE of issue 3180
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-21 10:33 UTC by SHOO
Modified: 2014-02-15 02:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description SHOO 2010-05-21 10:33:41 UTC
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 yebblies 2011-06-13 12:16:14 UTC
The underlying issue a dupe of bug 3180.

*** This issue has been marked as a duplicate of issue 3180 ***