-
-
Notifications
You must be signed in to change notification settings - Fork 668
Fix Issue 18578 - First enum value assigned 0 instead of EnumBaseType.init #7996
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
base: master
Are you sure you want to change the base?
Conversation
LemonBoy
commented
Mar 10, 2018
|
Thanks for your pull request and interest in making D better, @LemonBoy! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#7996" |
|
This changes the value of ditto for |
|
I see, the use of |
According to Jenkins (the project tester) this triggers a segfault in libasync. |
|
Also fails in Phobos with: |
|
Hmm, this change may end up breaking some stuff...let's do a deprecation cycle first (or add some warnings/errors) ? |
Warnings are often set to errors in some downstream projects, so deprecations are probably better here. |
|
It clearly will need a deprecation cycle. If |
|
Please include test case from https://github.com/dlang/dmd/pull/8090/files |
21fad14 to
6181a6f
Compare
|
I've rebased this on top of #8090, what's missing is to adjust the failures in phobos. |
|
This PR should fix the phobos issues: dlang/phobos#6368 |
|
Maybe it would be better to change the language specification than to change this, because this utterly breaks for floating point types. See further on in the specification:
So you'll get an enum whose every member is NaN or just a compile-time error, depending on which kind of equality is meant by "the same as". It also breaks for any |
|
Yeah maybe there is a better way to define how enum values are determined. However, we are talking about a case that doesn't make much sense in the first place, i.e. enum Foo : float
{
a, b
}What would you expect the value of |
That is worse than failing to compile IMO. |
Maybe...having all the members of an enum default to the same values does sound counter-intuitive to what an enum does, namely, enumerate a set of values. But I can't think of a use case where you would ever enumerate a set of values where float is the base type, unless you were explicitly assigning values to them, can you? |
|
Oh wait...I think I misunderstood you a bit. I guess you were saying it would be better to fail in this case rather than assigning every value to |
|
Please don't forget to update dlang.org's deprecation page as well. Please see dlang/DIPs#108 for an in draft process for deprecations of this nature. |
|
ping @LemonBoy . what's the status on this? |
Let's deprecate this behaviour that, according to the specification, is incorrect. Builds up on dlang#8090.
6181a6f to
1066b4d
Compare
|
@RazvanN7 status is rebased and green. |
| { | ||
| deprecation(em.loc, | ||
| "Enum `%s` has base type `%s` with non-zero .init; " ~ | ||
| "initialize the enum member explicitly", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message should indicate why. Namely that the default value will change in a later release.
Also, there's no changelog entry.
|
Removed auto-merge to give time to address feedback. I think it's important to tell the user why they need to take a certain action when something is deprecated. Also, deprecations need a changelog entry. |
|
I urge you all again to reconsider this. "The first element of an enum with base type T defaults to T.init" is very reasonable. "For every T, T.init should be an invalid value if possible" is reasonable. But combining the two leads to something very unreasonable.
This is going to break existing code. People will right ask why a char enum's first element being 0xff is useful or helps anyone write better programs. This new behavior is a bear trap. |
At the same time, I don't think enums based on |
|
I suspect we should just fix the spec to match the behavior. This won't break existing code, and seems to be what people expect anyway. |
|
Write a DIP |
|
@WalterBright in reality this affects enums of Note that the special enum |