Bug 22229 – Struct initialization via constructor missing from language spec
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-20T19:11:57Z
Last change time
2021-08-20T23:23:38Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Comments
Comment #0 by snarwin+bugzilla — 2021-08-20T19:11:57Z
A struct can be initialized with a value of a different type if it has a constructor that accepts a value of that type:
---
struct S
{
this(int n) {}
}
S s = 123; // ok: calls constructor
---
However, neither the language spec section on dynamic initialization of structs [1] nor the section on struct constructors [2] mention that constructors can be called with this syntax.
[1] https://dlang.org/spec/struct.html#dynamic_struct_init
[2] https://dlang.org/spec/struct.html#struct-constructor
Comment #1 by dlang-bot — 2021-08-20T19:16:34Z
@pbackus created dlang/dlang.org pull request #3090 "Fix Issue 22229 - Struct initialization via constructor missing from …" fixing this issue:
- Fix Issue 22229 - Struct initialization via constructor missing from language spec
https://github.com/dlang/dlang.org/pull/3090
Comment #2 by dlang-bot — 2021-08-20T23:23:38Z
dlang/dlang.org pull request #3090 "Fix Issue 22229 - Struct initialization via constructor missing from …" was merged into master:
- 2a63c9c5d61b845a0e1f676085e77d4938f65991 by Paul Backus:
Fix Issue 22229 - Struct initialization via constructor missing from language spec
https://github.com/dlang/dlang.org/pull/3090