www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Parsing bug?

reply Jean-Louis Leroy <jl leroy.nyc> writes:
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 { }`.
Apr 27 2020
parent reply RazvanN <razvan.nitu1305 gmail.com> writes:
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.
Apr 28 2020
parent reply RazvanN <razvan.nitu1305 gmail.com> writes:
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.
Apr 28 2020
parent Basile B. <b2.temp gmx.com> writes:
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
Apr 28 2020