-
-
Notifications
You must be signed in to change notification settings - Fork 606
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 Bugzilla 24582 - Detect unsafe cast(bool[])
#16558
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
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#16558" |
These are disallowed in `@safe` code with dlang/dmd#16558.
These are disallowed in `@safe` code with dlang/dmd#16558.
Dependant PR merged |
Like I mentioned on bugzilla, I don't see how these casts are unsafe. |
cast(bool[])
@dkorpel I added a comment there with an example: Only the runtime array cast is unsafe, the other 2 are OK - thanks. I need to update this pull to allow the literal cast, as well as change the error to a deprecation. |
Why is the cast being deprecated? Wouldn't it make more sense to simply fix the literal cast to create an array of 0 and 1s? For the sake of consistency, casting a literal or a variable shouldn't yield different results. |
It's not, it's disallowed in
That's what happens.
Currently it does, but changing that behavior is a breaking change and out of scope for this bug report. |
This comment was marked as resolved.
This comment was marked as resolved.
That would go against the spec: https://dlang.org/spec/expression.html#cast_array
So the raw data is not modified. |
For the runtime cast yes, but the literal cast is different: immutable c = cast(bool[]) [2, 4]; // literal cast applies to each element
pragma(msg, c); // [true, true] |
@dkorpel OK, sorry - so we are in agreement! |
REQUIRED_ARGS: -de | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/bool_cast.d(12): Deprecation: cast from `ubyte[]` to `bool[]` not allowed in safe code |
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.
(Not that you need to do this right away, but) can we link to/refer users to the spec section/other official documentation, as to why this is an unsafe operation? It was certainly not immediately obvious to me as to why this is the case.
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.
I've added a supplemental message for now.
Allow literal cast Make deprecation Add specific supplemental message
Tests now passing (other than 1 interop network request failure) |
Deprecate in safe code.