[Issue 24525] auto ref lambda exp not parsed if used as left-most expression in a expression statement

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 29 10:01:44 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24525

--- Comment #3 from basile-z <b2.temp at gmx.com> ---
> Any ambiguities in the grammar between Statements and Declarations are resolved by the declarations taking precedence.

yes, I remember the spec about decl/stmt ambiguities but here I think there are
none. 

The parser should lookup after `auto`. If next is `(` or if next two are `ref`
then `(`, then it should takes the path of expression.

> It is unfortunate that the function literal syntax starting `ref` or `auto ref` was added, when the function/delegate keyword starting forms can already handle those.

Indeed. But I'll show you the context:

```
void main()
{
    int a,b,c,d,cond;

    auto ref () {
        switch (cond)
        {
            case 1: return a;
            case 2: return b;
            case 3: return c;
            default: return d;
        }
    }() = 0;
}
```

Here, given the size of the lambda, you try to avoid the verbose solution (you
can put the lambda between parens however, but according to the specs, that
should work w/o).

--


More information about the Digitalmars-d-bugs mailing list