[Issue 12579] DMD rejects valid function literal
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 15 03:37:06 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12579
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to brian-schott from comment #0)
> void function() foo = {};
>
> According to the grammar spec, the latter should be parsed as a variable
> declaration whose type is "void function()", with a name of "foo" and an
> empty struct initializer. (By the way, the grammar does not allow empty
> struct initializers). This should not pass semantic analysis because a
> struct literal is not of type void function().
StructInitializer is defined as follows:
StructInitializer:
{ StructMemberInitializers_opt }
Between braces StructMemberInitializers is optional, so {} is properly
accepted.
And, If a delegate variable is initialized by empty StructInitializer, it is
treated as a function literal in semantic phase.
https://github.com/D-Programming-Language/dmd/blob/d4f778f96a85de9605a035864d3480e40097df28/src/init.c#L287
--
More information about the Digitalmars-d-bugs
mailing list