[Issue 18199] Error with lambda in struct initializer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 18 22:22:24 UTC 2018


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

John Belmonte <john at neggie.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|nobody at puremagic.com        |john at neggie.net

--- Comment #7 from John Belmonte <john at neggie.net> ---
Besides the code's documented case of "{}" (could be empty struct initializer
or empty parameterless function literal), there is another ambiguous case:

  static MyStruct foo = {
    { return 1 + 1; }
  };

where RHS could either be a struct initializer (with member type "int
function()") or function literal with a needless added scope.

In the "{}" case, the code sides with struct initializer.  This makes sense
since the function literal could be disambiguated in several ways (e.g. as
"function() {}").

Given that, I propose to resolve this bug as follows:

   1) document this other ambiguous case
   2) document why we side with struct literal in ambiguous cases (i.e. since
you can disambiguate function literal cases via extra syntax)
   3) change the parser to only abort struct literal look-ahead if semicolon or
return token appears at top level of curly brackets, so that struct initializer
may contain function literals

--


More information about the Digitalmars-d-bugs mailing list