Bug 1371 – Compiler rejects valid delegate.

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-07-25T04:01:51Z
Last change time
2018-11-23T23:24:14Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Aziz Köksal

Comments

Comment #0 by aziz.koeksal — 2007-07-25T04:01:51Z
// 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.
Comment #1 by Daniel919 — 2007-08-14T18:45:57Z
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
Comment #2 by k.hara.pg — 2011-06-18T01:21:09Z
Follwing still fails in trunk dmd 2.054 (d36b3b12fc4814e59f3a0d680b8700e787b1ceff). auto foo = { while (doSomething()){} }; Workarounds are as same.
Comment #3 by hsteoh — 2014-08-07T23:16:27Z
Still fails in git HEAD (2.067a). :-(
Comment #4 by iamthewilsonator — 2018-11-23T23:24:14Z
2.076.1 to 2.079.1: Failure with output: ----- onlineapp.d(4): Error: expression expected, not `while` onlineapp.d(4): Error: comma expected separating field initializers onlineapp.d(7): Deprecation: use `{ }` for an empty statement, not `;` ----- Since 2.080.1: Success with output: onlineapp.d(7): Deprecation: use `{ }` for an empty statement, not `;`