Is @trusted the wrong direction?
Dominikus Dittes Scherkl
dominikus at scherkl.de
Sun Nov 10 06:54:52 UTC 2019
On Saturday, 9 November 2019 at 23:44:06 UTC, anon5886 wrote:
> On Saturday, 9 November 2019 at 21:13:22 UTC, Dominikus Dittes
> Scherkl wrote:
>> On Saturday, 9 November 2019 at 20:38:47 UTC, Alexandru
>> Ermicioi wrote:
>>> ```d
>>> import std.stdio;
>>>
>>> T trusted (T)(T delegate() @system dg) @trusted {
>>> return dg();
>>> }
>>>
>>> void main() @safe
>>> {
>>> writeln("Hello D");
>>>
>>> ({
>>> writeln("C ", cast(void*) 1);
>>> }).trusted;
>>> }
>>> ```
>>>
>>> looks a lot better than anonymous functions that are called
>>> right away after being defined.
>>
>> Hmm. Only slightly better syntax, but more important doesn't
>> solve the other half of the problem: Forbidding non-lambda
>> trusted functions.
>>
>> The syntax I would prefer for trusted blocks is simply
>>
>> @trusted
>> {
>> }
>>
>> And everything between the @trusted and the opening bracket
>> (like function declarations) would be forbidden.
>
> Implementation is trivial... I got this to work in a small hour
> but the problem is that for now the safety really only works at
> the function level so the function properties have to be patch
> for the duration of the trusted block.
>
I don't see a problem with that. It's exactly what I expected
need to be done.
Cool. I'll test this.
>
> - prevent usage of trusted delegates
> - allow to infere @safe on func template containing these blocks
> - reduce the scope of the manual verification, supposed to be
> done for @trusted
More information about the Digitalmars-d
mailing list