Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit conversion in initializers doesn't work for subtypes #18573

Open
dlangBugzillaToGithub opened this issue Apr 29, 2013 · 1 comment
Open

Comments

@dlangBugzillaToGithub
Copy link

Andrej Mitrovic (@AndrejMitrovic) reported this on 2013-04-29T03:30:47Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=10006

Description

-----
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.
@dlangBugzillaToGithub
Copy link
Author

andrej.mitrovich (@AndrejMitrovic) commented on 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant