Local functions infer attributes?
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 27 20:08:05 PDT 2014
On 9/27/2014 7:56 PM, deadalnix wrote:
> On Sunday, 28 September 2014 at 02:42:29 UTC, Manu via Digitalmars-d wrote:
>> void f() pure nothrow @nogc
>> {
>> void localFunc()
>> {
>> }
>>
>> localFunc();
>> }
>>
>> Complains because localFunc is not @nogc or nothrow.
>> Doesn't complain about pure though.
>>
>> Is it reasonable to say that the scope of the outer function is
>> nothrow+ at nogc, and therefore everything declared within should also be
>> so?
>
> No as the function could be returned and used elsewhere, where these attribute
> aren't necessary. Also, inferring everything is quite expensive and we want D to
> compile fast.
>
> But maybe inference could be triggered on error ?
Since the function body is always present, inference should always be done. It
isn't costly. Should file an enhancement request on this.
More information about the Digitalmars-d
mailing list