Skip to content

[NFC] Refactor DerivedConformances code to reduce diagnostics code duplication #32884

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
merged 1 commit into from
Jul 14, 2020
Merged

[NFC] Refactor DerivedConformances code to reduce diagnostics code duplication #32884

merged 1 commit into from
Jul 14, 2020

Conversation

theblixguy
Copy link
Collaborator

This is a follow-up to #32797.

There was some code duplication for emitting new diagnostic notes for Comparable synthesis failures, so I have pulled the common code out for diagnosing derived conformance failures into separate functions which can be reused to emit the diagnostics.

  1. diagnoseAnyNonConformingMemberTypes diagnoses any members of the conforming type that does not conform to the protocol we were trying to synthesise the conformance to. For example, Comparable synthesis requires the members of the conforming type to also be Comparable and using this method we can diagnose any members which does not conform to Comparable.

  2. diagnoseIfSynthesisUnsupportedForDecl diagnoses the conforming type if we do not support derived conformances for that type. For example, Equatable synthesis is not supported for classes and using this method we can diagnose a given class type.

  3. storedPropertiesNotConformingToProtocol returns any stored properties of a struct which do not conform to a given protocol. For example, diagnoseNonConformingMemberTypes uses this method to find the struct members which do not conform to the type for which we're trying to synthesise the conformance to. It is also used in canDeriveConformance to figure out if we can synthesise Equatable or Hashable for a struct.

@theblixguy theblixguy requested a review from xedin July 14, 2020 21:09
@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@theblixguy theblixguy merged commit 6ea2034 into swiftlang:master Jul 14, 2020
@theblixguy theblixguy deleted the chore/nfc-refactor-derived-conformances-diagnostics-code branch July 14, 2020 23:49
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.

2 participants