-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[TypeChecker] SE-0352: Require coercion if result type contains existential(s) that would loose generic requirements #42559
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@DougGregor Please take a look to make sure that this is going in the right direction, I still need to implement this diagnostic for Self erasure cases but it shouldn't be too bad. |
45150b9
to
a95c827
Compare
xedin
commented
Apr 22, 2022
b57fd74
to
29ae2eb
Compare
29ae2eb
to
f309e4f
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
hborla
approved these changes
May 25, 2022
@swift-ci please smoke test |
DougGregor
reviewed
May 25, 2022
…ments Diagnose situations where inferring existential type for result of a call would result in loss of generic requirements. ```swift protocol P { associatedtype A } protocol Q { associatedtype B: P where B.A == Int } func getB<T: Q>(_: T) -> T.B { ... } func test(v: any Q) { let _ = getB(v) // <- produces `any P` which looses A == Int } ```
…rcion If there is going to be any loss of generic requirements in the result, a result of a call has to use explicit coercion.
For types like `<Base>.B.C` we need to check that neither `B` nor `C` have any additional requirements because they cannot be expressed in the existential type.
…would loose information Accessing members on the protocol could result in existential opening and subsequence result erasure, which requires explicit coercion if there is any loss of generic requirements.
…d of declaration Since the inference is a call site specific it makes sense to attach a candidate note to the call itself instead of the declaration used.
Instead of checking for presence of `where` clause, let's use requirement signature and check whether any of the requires are anchored on a particular associated type.
f309e4f
to
ec0b836
Compare
DougGregor
approved these changes
May 26, 2022
@swift-ci please test |
…ppressing opening at use site If erased result is passed as an argument to a call that requires implicit opening, the fix-it should use parens to avoid suppressing the opening at that argument position.
d8e40a1
to
8eba890
Compare
@swift-ci please test |
DougGregor
approved these changes
May 26, 2022
@swift-ci please test macOS platform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements SE-0352 revision - require explicit
as
coercion when existentialerasure loses information.
For example: