[AST] Choose an implied conformance source next to the type, if possible. #17832
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: Requirements for some stdlib protocols can be automatically synthesised if the conformance is declared (either on the type or in an extension) in the same file as the type declaration. This also works for implied conformances, e.g.
Hashable
inherits fromEquatable
meaning declaring conformance toHashable
can synthesiseEquatable
's==
requirement. If there was a second implied conformance in an earlier file (e.g. if some other file declaredextension Type: Comparable
) this overrode the one in the same file as the type, causing synthesis to fail.Scope: Fixing a regression since 4.1.
Origination: Caused by the change to allow synthesis in extensions, which meant that the code started to consider the other-file extension whereas previously it was completely ignored.
Risk: Low, little-to-no other code compares about the source file of an implied conformance.
Testing: CI tests.
Reviewed By: Slava Pestov
Fixes rdar://problem/41852654.
4.2 merge of #17786