D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10006 - Implicit conversion in initializers doesn't work for subtypes
Summary: Implicit conversion in initializers doesn't work for subtypes
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-29 03:30 UTC by Andrej Mitrovic
Modified: 2024-12-13 18:06 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-04-29 03:30:47 UTC
-----
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 Andrej Mitrovic 2013-04-29 03:32:28 UTC
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 dlangBugzillaToGithub 2024-12-13 18:06:31 UTC
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