Discussion Thread: DIP 1032--Function pointers and Delegate Parameters...--Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Fri Apr 10 09:40:12 UTC 2020


On 4/7/2020 2:36 PM, Steven Schveighoffer wrote:
> For example, if you have:
> 
> void foo(void delegate() dg) { dg(); }
> 
> Let's say I'm in a @nogc function, and I want foo to call my local lambda @nogc 
> delegate. Sure, I can pass in a delegate that is @nogc to this function, because 
> of the implicit cast allowed. but I can't actually call the function from that 
> context! It becomes useless.

This is still asking for (in effect) making foo() pure if the delegate is pure. 
This is just not going to work if foo() does much more than just call the 
delegate. Not many non-trivial functions can be pure, but delegates often are 
pure, because delegates are often trivial.

In order for your proposal to work, foo()'s implementation has to always be the 
most restrictive, i.e. it has to be `@safe nothrow pure @nogc`.


More information about the Digitalmars-d mailing list