-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Improve diagnostics for access level of protocol witness in extension. #22235
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
Conversation
In your examples:
|
@xwu Thanks for your inputs! If we follow the first one to update the code (i.e., replacing 'private' by 'internal'), we would get another warning as shown below.
So it makes sense to improve the diagnostics. If the proposed message is not concise, I have it rephrased as |
For the second one, I don't quite get your idea. I believe after the method is moved to another extension in the same file, it still can use those members declared 'private' in the original extension. For your advised change (i.e., marking extension as 'internal'), it may be a problem when other members in extension adopt the default access level. For the following example, after marking extension as 'internal',
|
@jrose-apple Hi Jordan, would you take a look at this, please? |
The implementation looks pretty good to me! |
…tension. If the access level of a protocol witness does not satisfies a requirement, the compiler suggests marking it as the required level. This is not suitable when the witness is in an extension whose specified access level is less than the required level, since the fixit fights with other warnings in this case. This patch identifies such case and produces improved diagnostics. Resolves: SR-9793
Thanks for the reply, Jordan! I updated the code as suggested. |
Build failed |
Build failed |
👍 |
@swift-ci Please test OS X platform |
swiftlang#22235 added an assert that was a little overzealous about the structure of access control attributes in the AST. It used to always expect that we reached diagnoseWitnessFixAccessLevel when there was an explicit mismatch in user-written access markers. But declarations may also have their access levels rewritten and their access attributes stripped if they are invalid. If you can get all of these to occur by the time you diagnose the witness, you see no attribute for a witness with insufficient ACLs for a requirement and crash. Relax the assert by using the formal access level and resolve rdar://56818960
If the access level of a protocol witness does not satisfies a requirement, the compiler always suggests marking it as the required level. This is not suitable when the witness is in an extension whose specified access level is less than the required level, since the fixit fights with other warnings in this case. This patch identifies such case and produces improved diagnostics.
Consider the following example, if we follow the original notes to mark
foo
andbar
as 'internal', we would get further warnings redundant 'internal' modifier and conflict with extension's default access, respectively. The diagnostics improved by this patch makes more sense. It uses removal (instead of replacement) fix-it forfoo
, and suggests movingbar
to another extension.Resolves SR-9793.