Skip to content
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

[SR-9218] Extending a protocol with self constraint to the same protocol should warn #51707

Closed
harlanhaskins opened this issue Nov 10, 2018 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers

Comments

@harlanhaskins
Copy link
Collaborator

Previous ID SR-9218
Radar None
Original Reporter @harlanhaskins
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee @theblixguy
Priority Medium

md5: 349a7184d8701fb6216495c50a251857

Issue Description:

vThe following code

protocol Foo {}
extension Foo where Self: Foo {}

should warn because the Self: Foo constraint is redundant.

@theblixguy
Copy link
Collaborator

@harlanhaskins: I believe this needs to be fixed in checkInheritanceClause in TypeCheckDecl.cpp, right? or perhaps in checkProtocolSelfRequirements?

@theblixguy
Copy link
Collaborator

After doing some research, seems like I need to check if the RHS of the where constraint is the same as LHS. I think this can be done in GenericSignatureBuilder::addTypeRequirement()

@theblixguy
Copy link
Collaborator

I guess I was wrong - the concrete type can be easily obtained, but not the subject type i.e the type of the subject is generic:

(generic_type_param_type depth=0 index=0 decl=test1.(file).Foo.Self)
(generic_type_param_type depth=0 index=0 decl=test1.(file).Foo extension.Self)

Basically, we want to get the type that the extension is extending (Foo, which is a protocol) and compare it to the constraintType (Foo). But the subject has no concrete type as it is generic. Maybe this isn't the right place to do the check? @harlanhaskins @xedin @belkadan @jckarter

@theblixguy
Copy link
Collaborator

PR: #20503

@harlanhaskins
Copy link
Collaborator Author

Thanks so much, @theblixguy!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants