www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1371] New: Compiler rejects valid delegate.

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

           Summary: Compiler rejects valid delegate.
           Product: D
           Version: 1.019
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: aziz.kerim gmail.com


// The compiler tries to parse this as a struct initializer.
auto foo = { while (doSomething()){} }; // Error: expression expected, not
'while'

There are several workarounds to this.

auto foo = { while (doSomething()){;} }; // Insert a semicolon somewhere.
auto foo = (){ while (doSomething()){} }; // Add a ParameterList.
auto foo = delegate void (){ while (doSomething()){} }; // A full delegate
expression.


-- 
Jul 25 2007
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1371


Daniel919 web.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.019                       |2.003




------- Comment #1 from Daniel919 web.de  2007-08-14 18:45 -------
string delegate() dg = { return "dg"; };
//Error: functions cannot return static array invariant char[2u]
//Error: cannot implicitly convert expression (__dgliteral1) of type int
delegate() to const(char)[] delegate()

string delegate() dg = { return cast(string) "dg"; }; //OK
//string delegate() dg = delegate string() { return "dg"; }; //OK
//auto dg = { return "dg".dup; }; //OK


-- 
Aug 14 2007