-
Notifications
You must be signed in to change notification settings - Fork 44
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
How is downcasting expected to work #658
Comments
|
Yup, that's the ones. I'll re-open this though, and use it to track finding a nicer way of doing these conversions. I'm considering |
Potentially just having better method names for these would help, I ultimately found them on |
I do wonder how this protocol type checking works. We have On those older releases |
To start with, upcasting to a protocol (e.g. To more specifically answer your question, upcasting to |
That's where the crux lies; this purely appears to be a getter which likely does not need to be Hence, if upcasting (as expected) doesn't do anything at runtime:
Just wanted to make sure an |
Same thing as happens elsewhere if you call a method on an object that isn't available; the runtime sees that there's no selector with that name, and you crash (safely, so not UB). So it would be perfectly fine for us to mark it as safe. If you want to call the method with a check at runtime first, you need to do the availability checking yourself:
We could, Besides, it'd be overly restrictive, there's many cases where Apple has introduced a protocol into an API, in a later version than the API itself was introduced.
No, as outlined above, the safety of an |
Not the safety, but the usefulness. Assuming a developer is on the latest (Beta) version of MacOS and relies on an infallible |
Yeah, that's a fair point. Again, the I once considered making method calls return an The way Swift and Objective-C solves this whole ordeal is with compiler warnings, which we can't do as we're just a library. I am thinking of ways to work around this (see again #266), but it's fairly difficult, and my current ideas would still require testing at runtime. (I'm not sure how my tone sounds here, I fear I may sound a little dismissive because I feel pretty certain in the chosen solution at this point (i.e. do nothing), but wanted to state that I'm glad to have this discussion (!), and I am open to try changing my viewpoint) |
I align exactly with the chosen solution, i.e. do nothing. Specifically because, while the original issue description may make it sound like this is an ordinary One might hence expect any upcasting-like API like the proposed I'll leave it to you to consider the best API to describe this, just glad that we're on the same page when it comes to these "inherited protocols" to really be optional. |
For what it's worth, for me this issue was mostly about the discoverability of a casting API (either direction), not so much about the possibility of being able to. The only casting api I could find at the time was on Retained, while I needed to casting a ProtocolObject. I had seen the from_ref and from_retained apis before but never connected the dots that these were for casting. |
I'm currently on the latest commit, trying to create a
MTLAllocation
from aMTLHeap
can I can't figure it out.Technically a
ProtocolObject<dyn MTLHeap>
, I seem to hit this problem every so often and need increasingly arcane methods of casting these down. Similar forRetained
objects. Both would be extremely welcome to have acast
function that would convert from U to T where U:T.The text was updated successfully, but these errors were encountered: