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-13039] Confusing diagnostic about protocol type not conforming to protocol #55485
Comments
@swift-ci create |
A few quick notes if you’re tackling this as a starter bug:
|
Also, if something is unclear, feel free to ask a question, and feel free to @ me (varungandhi-apple) or Brent (@ brentdax) for code review on your PR. |
Please tag me (@hborla) in your PR as well! And yes, please ask questions if you need help. |
Comment by Onyekachi Ezeoke (JIRA) theindigamer (JIRA User)
Then I can run the test, according to the documentation. |
In the general case, we will have an error like Value of protocol type 'Q' cannot conform to 'P'; only struct/enum/class types can conform to protocols There are two cases here: 1. When Q = P, or more generally when Q refines P. What I meant by "perhaps special casing when the two protocols are related" was that it might make sense to have two diagnostics: one diagnostic for case 1 and a different diagnostic for case 2. Why? Case 1 is likely to be hit more frequently in practice, and we have more information available, so it would be worthwhile to have a more informative message for it. For example, if A value of protocol type 'Q' does not conform to the protocol itself (exception: 'Error'); only concrete types such as structs, enums and classes can conform to protocols. The educational note could also focus on the Q = P case first for simplicity and then go the the general case. This is not strictly necessary, but I think it would help understanding the specific case before the general case. > I have read some documentations about diagnostic and I currently want to add the educational notes first before addressing the first concern. Sure. That seems reasonable. > While going through the documentation, they wasn't mentioned if they is any special naming convention for file in userdocs/diagnostics/ There isn't as far as I can tell. Looking at the other ones, if the title is short, then it is the title, otherwise, it is a shorter version of the title. Maybe > Is code snippet required in the educational notes. It would be valuable to provide some code snippets showing where the error comes up. You can look at I think you have the right steps for the educational note, that matches what is in |
Comment by Onyekachi Ezeoke (JIRA) theindigamer (JIRA User) Thanks so much for this wonderful explanation, you addressed all my questions very well. |
Comment by Owen Voorhees (JIRA) theindigamer (JIRA User) onyekachi (JIRA User) Yeah, there's no specific naming convention for the markdown files. Any name that's relatively short and uses dashes between the words is good, currently we don't display the filenames to users anywhere. Feel free to let me know if there's anything else in docs/Diagnostics.md that's unclear or would be helpful to mention! |
Comment by Onyekachi Ezeoke (JIRA) owenvoorhees (JIRA User) Thanks for the confirmation, I will surely let you know if I need any further clarification. |
Comment by Onyekachi Ezeoke (JIRA) @theblixguy Sorry I had to bring this conversation down here, I don't want to clutter the PR with too many Asks. This is as regards to your last suggestion: I think you need two separate diagnostics here - one for a generic “does not conform” and one for self-conformance, and when protocols are related, etc and update the code so it emits one of them depending on the types. I have looked into the code in order to know where to effect the code change, I have checked the **ERROR** macro declaration and how it was used in the DiagnosticsSema.def file, I would say I don't currently understand how all the pieces work together. Is there any form of documentation that would help me understand more how all the pieces work? Which part of the code do I modify so that it emits any of the diagnostics depending on the type? Do I have to contain the messages in one **ERROR** macro in DiagnosticsSema.def file and have the logic determine which one to emit? Sorry for asking too much, I am still pretty new here. Thanks. |
Yeah, you can either put the message in a single ERROR diagnostic or split them into two. If you decide to use a single diagnostic, you can use Let’s settle on the diagnostic text/structure first and once that’s done, we can take a look at the code and tweak it (if necessary) to incorporate the new diagnostics. |
Comment by Onyekachi Ezeoke (JIRA) Alright, I will do that. Thanks @theblixguy. |
PR link: #32524 |
theindigamer (JIRA User) Seems PR was merged, should this be closed? |
Done. |
Additional Detail from JIRA
md5: befe388ccc5ea473d8c09a9363e670f5
Issue Description:
For example, one might see an error like:
> Value of protocol type 'Cancellable' cannot conform to 'Cancellable'; only struct/enum/class types can conform to protocols
Hamish has written a great answer here: https://stackoverflow.com/a/43408193 .
1. We should make this diagnostic clearer (perhaps special casing when the two protocols are related), as it may not be obvious to the reader why this is not the case.
2. We should probably have an educational note for this.
The text was updated successfully, but these errors were encountered: