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

Steven Schveighoffer schveiguy at gmail.com
Fri Apr 3 13:08:40 UTC 2020


This is a significant breaking change.

This is very common:
struct S
{
    private int delegate() _dg;
    @property void dg(int delegate() newdg) @safe pure nothrow { _dg = 
newdg; }
    @property auto dg() @safe pure nothrow inout { return _dg; }
}

The breaking changes and deprecations seems to downplay this scenario, 
reporting a very obscure "save these to a global" scenario.

The D world is full of types that store delegates, with setters and getters.

I would recommend having an opt-in attribute for this. Something like auto:

@safe pure nothrow @nogc
int foo(int delegate() auto dg, int function() auto fp)

There is also no discussion of templates, which infer attributes. What 
happens there? It's more complicated than at first glance, as the 
delegates passed can currently influence the template attribute detection.

e.g.:

T foo(T)(T delegate() dg, T function()) { return dg() + fp(); }

@system nothrow @nogc
{
   int delegate() dg1;
   int function() fp1;
}

@safe pure
{
   int delegate() dg2;
   int function() fp2;
}

foo(dg1, fp1);
foo(dg2, fp2);

Are these different template instantiations? If not, then you can 
ironically turn off delegate/function-pointer inferred attributes by 
making something a template.

-Steve


More information about the Digitalmars-d mailing list