Bug 10006 – Implicit conversion in initializers doesn't work for subtypes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-29T03:30:47Z
Last change time
2024-12-13T18:06:31Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#18573 →

Comments

Comment #0 by andrej.mitrovich — 2013-04-29T03:30:47Z
----- struct S { float value = 0.0; alias value this; } float f = 250.0; // ok S s = 250.0; // ng void main() { } ----- Error: cannot implicitly convert expression (250.000) of type double to S I think the above should work.
Comment #1 by andrej.mitrovich — 2013-04-29T03:32:28Z
This does give me an idea for a DIP: struct S { float value = 0.0; alias value this; // called only when a *literal* is provided this(enum double val) { } } This would enable creating custom implicit conversions when initializing a struct with a literal of some sort.
Comment #2 by robert.schadek — 2024-12-13T18:06:31Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18573 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB