Skip to content

[AST] Choose an implied conformance source next to the type, if possible. #17832

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

huonw
Copy link
Contributor

@huonw huonw commented Jul 9, 2018

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 from Equatable meaning declaring conformance to Hashable can synthesise Equatable's == requirement. If there was a second implied conformance in an earlier file (e.g. if some other file declared extension 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

huonw added 2 commits July 9, 2018 14:30
…nce tests.

The special handling of interleaved decls and statements is confusing and makes
other testing hard.
…ble.

If a conformance to a protocol is implied by several other
conformances (i.e. protocol P: Equatable {} and protocol Q: Equatable {} and a
type declares conformance to both P and Q), we should choose a source that's in
the same file as the type, if we can, because automatic synthesis of
conformances (for Equatable, Hashable, etc.) only works in that case.

Fixes rdar://problem/41852654.
@huonw
Copy link
Contributor Author

huonw commented Jul 9, 2018

@swift-ci please test

@huonw
Copy link
Contributor Author

huonw commented Jul 9, 2018

@swift-ci please nominate

@huonw huonw merged commit 873416f into swiftlang:swift-4.2-branch Jul 9, 2018
@huonw huonw deleted the crossfile-synthesis-implication-4.2 branch July 9, 2018 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant