www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12074] New: Add BlockStatement to TemplateSingleArgument

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12074

           Summary: Add BlockStatement to TemplateSingleArgument
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: thecybershadow gmail.com



13:03:40 EET ---
Currently, this is forbidden, both by the specification and implementation:

int call(alias fun)()
{
    return fun();
}

int main()
{
    return call!{ return 5; }();
}

It seems unambiguous, so I see no reason why it should not be allowed.

Perhaps the same idea applies to array/AA literals.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 04 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12074




13:09:00 EET ---
I see Kenji posted a patch in 2010 here:

http://d.hatena.ne.jp/khara_9rnsr/20100927/1285572362

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 04 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12074




13:40:23 EET ---
Kenji's patch is now outdated (not surprising). However, this very simple patch
seems to work just fine:

diff --git a/src/parse.c b/src/parse.c
index 78a2356..088326d 100644
--- a/src/parse.c
+++ b/src/parse.c
   -2360,6 +2360,8    Objects *Parser::parseTemplateArgument()
         case TOKfuncstring:
         case TOKprettyfunc:
         case TOKthis:
+        case TOKlcurly:
+        case TOKlbracket:
         {   // Template argument is an expression
             Expression *ea = parsePrimaryExp();
             tiargs->push(ea);

The original patch explicitly set the expression type to that of a function.
This doesn't seem to be necessary, as the compiler now infers whether it is a
function or delegate literal depending on whether statements refer to the
literal's context.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 04 2014