D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7061 - delegates sometimes cannot be used in struct initializers
Summary: delegates sometimes cannot be used in struct initializers
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-12-03 06:27 UTC by timon.gehr
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011-12-03 06:27:46 UTC
S a = {{}};              // fail
S b = {{;}};             // fail
S c = {{x=0;}};          // fail
T d = {{return 0;}};     // fail

void main(){
    S x = {{}};          // ok
    S y = {{;}};         // fail
    S z = {{x=0;}};      // fail
    T w = {{return 0;}}; // fail
}

The program should compile. The inconsistency between x and y suggests that the issue is partly related to the parser.
Comment 1 Vladimir Panteleev 2017-07-02 01:47:19 UTC
Timon, fairly sure that's not the entire program. What's the definition of S?
Comment 2 timon.gehr 2017-07-02 03:37:34 UTC
(In reply to Vladimir Panteleev from comment #1)
> Timon, fairly sure that's not the entire program. What's the definition of S?

Oops. Thanks! The entire program:

struct S{ void delegate() dg; }
struct T{ int delegate() dg; }

int x;
S a = {{}};              // fail
S b = {{;}};             // fail
S c = {{x=0;}};          // fail
T d = {{return 0;}};     // fail

void main(){
    S x = {{}};          // ok
    S y = {{;}};         // fail
    S z = {{x=0;}};      // fail
    T w = {{return 0;}}; // fail
}
Comment 3 basile-z 2019-07-23 01:25:00 UTC
struct S{ void delegate() dg; }
struct T{ int delegate() dg; }

int x;
S a = {{}};              // ok
S b = {{;}};             // ok
S c = {{x=0;}};          // ok
T d = {{return 0;}};     // ok

void main(){
    int g;
    S x1 = {{}};            // ok
    S y = {{;}};            // ok
    S z = {{x=0;}};         // ok
    T w = {{return 0;}};    // ok
}