Bug 21547 – Oder of constructor declaration affects struct initializer
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2021-01-14T09:16:53Z
Last change time
2021-01-17T11:33:12Z
Keywords
pull
Assigned to
No Owner
Creator
RazvanN
Comments
Comment #0 by razvan.nitu1305 — 2021-01-14T09:16:53Z
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.
Comment #1 by razvan.nitu1305 — 2021-01-14T09:22:37Z