DIP 1003 Formal Review
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Thu May 25 18:23:59 PDT 2017
On 25.05.2017 20:57, MysticZach wrote:
> On Thursday, 25 May 2017 at 11:49:47 UTC, MysticZach wrote:
>> ...there is no known possibility of semantic confusion between the two
>> potential uses of `body`,
>
> I spoke too soon. I found a place where such semantic ambiguity is
> possible. It can only occur in interface declarations, and will not
> exist in any currently compilable D code, as it requires `body` to be an
> identifier to be legal in the first place.
>
> Currently, the only place in D where you can declare a function that has
> a contract, but no body, is in an interface. D syntax, it turns out,
> does not require a semicolon at the end of such declarations.
> Referencing https://dlang.org/spec/interface.html#interface-contracts we
> have:
>
> interface I
> {
> int foo(int i)
> in { assert(i); } // <-- no semicolon required
>
> void bar();
> }
>
> Therefore, with `body` as an identifier, you might have this ambiguity:
>
> struct body {}
>
> interface I {
> int foo(int i)
> in { assert(i); }
>
> body bar();
> }
>
> The ambiguity is fixable by modifying the parser to look ahead after
> `body` for `{`. Since virtual interface functions are not even allowed
> to have bodies, if it finds `{`, then `body` should be interpreted as a
> keyword, and an error issued. In all other cases `body` should be
> interpreted as an identifier.
>
> This is not a hard problem, but it is indeed a semantic ambiguity, so it
> bears mentioning.
There is no ambiguity, because only one valid interpretation exists.
More information about the Digitalmars-d
mailing list