[5.0] Don't fix access of an 'open' decl in a 'public' extension #22216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: This is reasonable to diagnose with a warning, but dropping the 'open' down to 'public' isn't the right fix, because it might have been an override or satisfying a protocol requirement. In that case, the declaration would have to get moved to another extension instead, or the extension has to not set a default access level.
This turned out to be a source compat issue because the same logic that emits the fix-it also updates the access of the member, which then resulted in "must be as accessible as the declaration it overrides" in the same build. It's not immediately clear what caused this to work in 4.2 but result in an error in 5.0; probably something's just being validated in a different order than it was before. The change makes sense either way.
Stepping back, it's weird that a warning would change how the compiler saw the code, and while we could check for 'override' explicitly, we can't know if the member might be satisfying a protocol requirement. Better to just not guess at the right answer here.
Scope: Affects members of extensions with a greater level of access than the extension's default.
Issue: rdar://problem/47557376&28493971
Risk: Low. We're choosing not to emit a fix-it (basically no risk), making sure we emit another diagnostic (for something that would never work), and not changing the AST from what the user wrote (a behavior change, but one that matches different source the user could have written).
Testing: Updated/added compiler regression tests, passed source compatibility suite.
Reviewed by: @brentdax, @dingobye