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
[SR-7015] Fix CoreFoundation conditional downcast diagnostic message #14956
[SR-7015] Fix CoreFoundation conditional downcast diagnostic message #14956
Conversation
This message is not grammatically correct. It also doesn't provide much clarity: check each CFTypeID...for what? |
Thanks to see my PR. CFTypeIDs is written in When I wrote _ = string as? CFArray , error with message I'll try to replace other message representing correct status. |
I pushed new commit. BeforeWithout
|
Thanks for the continued effort. Writing diagnostic messages is very hard, so I don't envy your task. Jordan Rose wrote a very good guide about Swift diagnostic messages which I would recommend to you. The original diagnostic message isn't, in fact, wrong. The Swift bug SR-7015 is pointing out that the message doesn't present any information about what the user should do about the problem. The challenge is to write something else very succinctly that will teach the user how to fix the problem correctly. It's not enough to say that something should be "checked"--you need to find a way, in very few words, to explain what should be checked or how. |
Thanks to give me information and I perhaps understood where my error message was wrong. Message before and after were same for user. Now I think I want to try giving message usefully as same as in case of |
I pushed new commit. I found some difficulties to check type directly. (For example, CSApply.swift, SwiftObject.mm) Before// Conditional downcast to CoreFoundation type 'CFData' will always succeed
_ = string as? CFData After// Conditional downcast to CoreFoundation type 'CFData' will always succeed; did you mean to use 'as' to downcast?
_ = string as? CFData
// ↓ replace as? to as
// 'String' is not convertible to 'CFData'; did you mean to use 'as!' to force downcast?
_ = string as CFData I think actually explanation of error message is some what wrong but user can know mismatch |
@xwu I'm glad if you see commit and write what do you think when you have a time! |
If I understand correctly, your change causes the compiler to suggest a fix that doesn't work? |
@xwu Thank you for your message🙏🏻 Yes, if only once replacing. Message from SR-7015 is There are many codes to fix this optional cast problem. So I think the way is implementing codes to compare CFType and others in case optional cast or escaping to already solved situations. I only can escaping way just now. Do you think should I implement complete suggestion? |
@xwu I decide to close this PR and I'll create more meaningful fix if possible! Thanks to spend of your time!! |
Thanks for your effort. I'm not sure I understand what you're asking, but it's challenging to write good error messages. I'm still not sure, after this discussion, what the answer is to the question: when this error occurs, how do I fix my code? Your fix should answer that question. |
Fix error message about CoreFoundation conditional downcast diagnostic more helpful for user.
Resolves SR-7015.