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
It seems like this a regression from 2.093.1. Offending PR: https://github.com/dlang/dmd/pull/11159
Comment #2 by dlang-bot — 2021-01-14T10:07:45Z
@RazvanN7 created dlang/dmd pull request #12132 "Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully" fixing this issue: - Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully https://github.com/dlang/dmd/pull/12132
Comment #3 by dlang-bot — 2021-01-17T11:33:12Z
dlang/dmd pull request #12132 "Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully" was merged into master: - b61df05dd3d5d9792452c496d07fe04f2df12993 by RazvanN7: Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully https://github.com/dlang/dmd/pull/12132