Bug 12338 – @trusted delegates should implicitly cast to @safe
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-10T11:11:00Z
Last change time
2014-03-14T06:42:50Z
Assigned to
nobody
Creator
destructionator
Comments
Comment #0 by destructionator — 2014-03-10T11:11:07Z
@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.
Comment #1 by devw0rp — 2014-03-10T11:13:56Z
I think the same idea applies to 'void function() @safe' as well, as you could trivially wrap any @trusted function in a @safe function.
Comment #2 by yebblies — 2014-03-14T06:36:35Z
&bug is not a delegate, it is a function. @trusted delegates do convert to @safe delegates.
Comment #3 by destructionator — 2014-03-14T06:42:50Z
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.