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-11308] Classes should be allowed as extended types with where clauses #53709

Open
typesanitizer opened this issue Aug 14, 2019 · 8 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@typesanitizer
Copy link

Previous ID SR-11308
Radar rdar://problem/54314762
Original Reporter @typesanitizer
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: 0837dece926acd2ecc6ca51c66fcf8ee

Issue Description:

The following code compiles:

protocol P {}
class C {}
extension P where Self : C {}

but if you flip things around, it stops compiling

extension C where Self : P {}

with "error: trailing 'where' clause for extension of non-generic type 'C'".

It is not clear whether this is intended behavior or a bug (I think different people have different opinions on this), so I've opened this bug report so we can discuss it in one place.

@typesanitizer
Copy link
Author

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by Owen Voorhees (JIRA)

This sounds sort of like https://bugs.swift.org/browse/SR-5260 to me in that if this was allowed, flipping the order would have a slightly different meaning w/ regard to access control. Doesn't seem like a reason to disallow it though.

@typesanitizer
Copy link
Author

owenvoorhees (JIRA User) In my opinion, SR-5260 is more of a distinct feature ("allow protocol compositions in extended types") than this one. We already allow classes in extended types today, only without 'where' clauses.

Also, the concern raised there was about Swift 4. I'm not sure if Swift 5 shares the same access control model.

@belkadan
Copy link
Contributor

It does. The only changes to access control between Swift 4 and Swift 5 were patching holes (things that should not have been allowed in Swift 4's model that went undiagnosed).

@typesanitizer
Copy link
Author

cc @slavapestov @DougGregor for opinions.

@belkadan
Copy link
Contributor

(I'm of the opinion that this should be allowed for non-final classes but I also see why it's annoying to implement.)

@slavapestov
Copy link
Member

Intuitively I can see why this should be allowed to work, however "Self" is not a type parameter that can be constrained in class extensions. I think it would be a fairly big change to make this work. For one, it would change the mangling in all class extensions, since the type of "self" would now be a type parameter and not a class.

@belkadan
Copy link
Contributor

We could limit that to extensions of classes that actually constrain Self, at least, but yeah.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

4 participants