Thread overview
Parsing bug?
Apr 27, 2020
Jean-Louis Leroy
Apr 28, 2020
RazvanN
Apr 28, 2020
RazvanN
Apr 28, 2020
Basile B.
April 27, 2020
import std.traits;

unittest
{
  struct attr;
  void foo() {}
  ReturnType!foo bar(int a) {}
  void baz(@attr int a) {}
  ReturnType!foo blah(@attr int a) {}
}

dmd -c -unittest bug.d
bug.d(9): Error: found `blah` when expecting `;` following statement
bug.d(10): Error: found `}` when expecting `;` following statement
bug.d(11): Error: found `End of File` when expecting `}` following compound statement

This goes away if I remove `unittest { }`.

April 28, 2020
On Monday, 27 April 2020 at 22:48:46 UTC, Jean-Louis Leroy wrote:
> import std.traits;
>
> unittest
> {
>   struct attr;
>   void foo() {}
>   ReturnType!foo bar(int a) {}
>   void baz(@attr int a) {}
>   ReturnType!foo blah(@attr int a) {}
> }
>
> dmd -c -unittest bug.d
> bug.d(9): Error: found `blah` when expecting `;` following statement
> bug.d(10): Error: found `}` when expecting `;` following statement
> bug.d(11): Error: found `End of File` when expecting `}` following compound statement
>
> This goes away if I remove `unittest { }`.

Yes, this is a parser bug. `unittest` isn't important here (you can replace unittest with a function declaration and the behavior will be the same), it's the fact that you are declaring a nested function which returns a template instance  that confuses the parser. Please file this on bugzilla.
April 28, 2020
On Tuesday, 28 April 2020 at 07:41:28 UTC, RazvanN wrote:
> On Monday, 27 April 2020 at 22:48:46 UTC, Jean-Louis Leroy wrote:
>> [...]
>
> Yes, this is a parser bug. `unittest` isn't important here (you can replace unittest with a function declaration and the behavior will be the same), it's the fact that you are declaring a nested function which returns a template instance  that confuses the parser. Please file this on bugzilla.

I forgot about the UDA. It looks like the parser expects a type after the `(` and discovering the UDA makes it error.
April 28, 2020
On Tuesday, 28 April 2020 at 07:43:13 UTC, RazvanN wrote:
> On Tuesday, 28 April 2020 at 07:41:28 UTC, RazvanN wrote:
>> On Monday, 27 April 2020 at 22:48:46 UTC, Jean-Louis Leroy wrote:
>>> [...]
>>
>> Yes, this is a parser bug. `unittest` isn't important here (you can replace unittest with a function declaration and the behavior will be the same), it's the fact that you are declaring a nested function which returns a template instance  that confuses the parser. Please file this on bugzilla.
>
> I forgot about the UDA. It looks like the parser expects a type after the `(` and discovering the UDA makes it error.

in parser.d, isParameters() does not check the attributes.
issue + patch : https://issues.dlang.org/show_bug.cgi?id=20780