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

Named enum construction from base type is inconsistent #20543

Open
dlangBugzillaToGithub opened this issue Nov 9, 2024 · 1 comment
Open
Labels

Comments

@dlangBugzillaToGithub
Copy link

Nick Treleaven (@ntrel) reported this on 2024-11-09T16:35:12Z

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

Description

The following is an error:
```
enum E : int;
E e = E(4);
```

enumbase.d(2): Error: cannot implicitly convert expression `4` of type `int` to `E`

Which is consistent with uniform construction because a base type instance does not implicitly convert to the enum type. But this compiles:

```
struct S {
    this(int) {}
}

enum E : S;
E e = E(2);
```

However, an instance of S does not implicitly convert to E, so this is inconsistent.

The spec does not seem to mention enum construction with an argument list.
There is a test in dmd for issue 16346 to allow E(E.member), presumably for generic code.
@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2024-11-09T17:28:53Z

There is also a dmd test case for issue 23778 using construction from base struct. So it would need to be deprecated.

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

No branches or pull requests

1 participant