digitalmars.D.bugs - [Issue 21547] New: Oder of constructor declaration affects struct
- d-bugmail puremagic.com (44/44) Jan 14 2021 https://issues.dlang.org/show_bug.cgi?id=21547
https://issues.dlang.org/show_bug.cgi?id=21547 Issue ID: 21547 Summary: Oder of constructor declaration affects struct initializer Product: D Version: D2 Hardware: x86_64 OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: razvan.nitu1305 gmail.com struct Bar { disable this(int a) {} this(int a, int b) {} string a; uint b; } void main () { Bar b = { a: "Hello", b: 42 }; } Compiles fine. Whereas: struct Bar { this(int a, int b) {} disable this(int a) {} string a; uint b; } void main () { Bar b = { a: "Hello", b: 42 }; } Gives: test.d(12): Error: struct `Bar` has constructors, cannot use `{ initializers }`, use `Bar( initializers )` instead Expected result: both examples give the same error. The problem is that the compiler checks the first declared constructor and if it is disabled it considers that the struct does not have any other constructors. It should check the entire overload set. --
Jan 14 2021