www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12338] New: trusted delegates should implicitly cast to safe

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12338

           Summary:  trusted delegates should implicitly cast to  safe
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: destructionator gmail.com


--- Comment #0 from Adam D. Ruppe <destructionator gmail.com> 2014-03-10
11:11:07 PDT ---
 safe void test(void delegate()  safe dg) {
        dg();
}

 trusted void bug() { }

void main()  safe {
        test(&bug);
}

safety.d(8): Error: function safety.test (void delegate()  safe dg) is not
callable using argument types (void function()  trusted)


I think that should work since  trusted functions can normally be called by
 safe functions, so the delegate should implicitly cast too.

Note that if you change the call line to this:

        test({ bug(); });

It will compile - the anonymous delegate is inferred as  safe.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12338


w0rp <devw0rp gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |devw0rp gmail.com


--- Comment #1 from w0rp <devw0rp gmail.com> 2014-03-10 11:13:56 PDT ---
I think the same idea applies to 'void function()  safe' as well, as you could
trivially wrap any  trusted function in a  safe function.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12338


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |INVALID


--- Comment #2 from yebblies <yebblies gmail.com> 2014-03-15 00:36:35 EST ---
&bug is not a delegate, it is a function.   trusted delegates do convert to
 safe delegates.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 14 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12338



--- Comment #3 from Adam D. Ruppe <destructionator gmail.com> 2014-03-14
06:42:50 PDT ---
Well, that's embarrassing, it even said that in the error message I
copy/pasted!

But yeah, i just double checked, it does indeed work with functions and
delegates both if you pick the right one.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 14 2014