-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Fix Issue 21279 - cast expression between integer types is not defined #3373
Conversation
|
Thanks for your pull request and interest in making D better, @ntrel! 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 references
|
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 two paragraphs seem to be overlapping in what they are specifying.
Both statements talk about signed values. I'm not exactly sure what the need for the second paragraph is.
spec/expression.dd
Outdated
|
|
||
| ubyte e = 255; | ||
| auto f = cast(byte) e; | ||
| assert(f == -1); |
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.
This is somewhat of a bad example, because ubyte doesn't need a cast for byte.
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.
Yes, byte f = e; works implicitly. But I'm hoping there will be a warning or error for that eventually. So I think it's good practice to cast when the values might not fit.
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 point I'm making is that there is no special rule for casting, as this implies.
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.
Now that I'm looking for it, I also don't see anything in the spec on implicit conversions between types for assignment! Though it hints at it in the example here: https://dlang.org/spec/type.html#usual-arithmetic-conversions
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.
@schveiguy I have changed these to implicit conversions. I think it's OK to keep them under the cast docs as the first floating point example is also implicit conversions, not casts.
The first paragraph is about truncating to a smaller type. The first example shows this can flip the sign even when the source and target are both signed. The second paragraph is about differing signedness of source and target types. |
No description provided.