DIP 1003 Formal Review

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Sun May 14 07:06:01 PDT 2017


On 5/14/17 9:53 AM, Petar Kirov [ZombineDev] wrote:

> Edit: I may be wrong. Here's a case that's on the edge of ambiguity:
>
> void main()
> {
>     void inner(int x)
>     in { }
>     {
>         writeln("WAT");
>     }
> }
>
> If 'body' was optional, what would be the output of the program? It
> turns out
> that the output would be empty, because function bodies are required for
> functions
> with 'in' or 'out' contracts, making the block bind to the 'inner'
> function,
> instead of 'main'.
>

I don't think this is ambiguous or controversial. We are used to a block 
that follows a function declaration being that function's body without a 
special keyword.

Look at it this way:

void inner(int x) // in {}
{
    writeln("Yeah, this is normal");
}

If you uncomment the in clause, it's still pretty normal looking.

Not that I'm particularly arguing for making body always optional, I'm 
fine with continuing to require it. But it's also fine to make it 
optional IMO.

-Steve


More information about the Digitalmars-d mailing list