Skip to content

[Sema] Warn about redundant ': Any' conformances #17242

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

Closed
wants to merge 2 commits into from

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Jun 15, 2018

This is the first half of the implementation to warn about : Any conformances and constraints (I decided to split it up as the implementation for the removal fix-its for constraints in the generic signature builder is proving to be more involved than I thought it would).

In this PR is the logic that deals with conformances. Note that we avoid dealing with protocols and generic placeholders in the added logic, as that will be covered by a follow-up PR that diagnoses redundant : Any constraints in the generic signature builder (and checkInheritanceClause can get called more than once when dealing with generic signatures, which would incorrectly lead to multiple warnings being emitted in that case).

Resolves SR-8008.

- Protocol decls don't have explicit generic parameters, so don't use their location.
- Get the location of the extended type token rather than the end brace token.

Neither of these paths are being exercised yet, so no tests to accompany.
Such a stated conformance is always redundant. This patch purposefully ignores conformance constraints that are parsed as inheritance clauses, such as with protocols and generic placeholders (e.g '<T : Any>'). These are best diagnosed in the generic signature builder.
"redundant conformance of %0 to %1", (Type, Type))
NOTE(all_types_implicitly_conform_to,none,
"all types implicitly conform to %0", (Type))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative phrasing for the note would be "all types are subtypes of %0", which is more technically correct for Any as it's not actually a protocol you can conform to (just an empty protocol composition) – but I feel the current wording is more user friendly. Thoughts?

@hamishknight
Copy link
Contributor Author

Superseded by #17425

@hamishknight hamishknight deleted the warn-conform-any branch June 22, 2018 16: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.

1 participant