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

Fix Issue 21279 - cast expression between integer types is not defined #3373

Merged
merged 3 commits into from
Aug 26, 2022

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Aug 15, 2022

No description provided.

@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
21279 normal cast expression between integer types is not defined

Copy link
Member

@schveiguy schveiguy left a 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.


ubyte e = 255;
auto f = cast(byte) e;
assert(f == -1);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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.

@ntrel
Copy link
Contributor Author

ntrel commented Aug 16, 2022

Both statements talk about signed values. I'm not exactly sure what the need for the second paragraph is.

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.

@dlang-bot dlang-bot merged commit 2f83582 into dlang:master Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants