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-10484] Restriction against Self in class types appears(?) to be needless #52884

Closed
dabrahams opened this issue Apr 14, 2019 · 2 comments
Closed
Labels
compiler The Swift compiler in itself improvement

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-10484
Radar None
Original Reporter @dabrahams
Type Improvement
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: db5b1fdcc8d8bafd0a998853cf91e790

Issue Description:

Unless I'm missing something, the code below indicates we could, effectively, generate a protocol the first time someone uses `Self` in a class in a way that is currently prohibited.

class X {
    final func f(_: Self) {} // Can't use Self here!
}

// Okay, I'll do something equivalent, then!
class Y : YProtocol {}
protocol YProtocol : Y {}
extension YProtocol {
    func f(_: Self) {} // Works fine.
}
@belkadan
Copy link
Contributor

Those two Self identifiers aren't equivalent. :-( The one in the class is the dynamic type, implying that if someone subclasses X, they can only call f on that subclass with another instance of the same subclass. In the protocol case, it's the type that originally conformed to the protocol, which is Y, and any subclass instances will get upcasted to Y when calling f.

@dabrahams
Copy link
Collaborator Author

Gag me with a spoon.

Thanks, Jordan!

@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
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

2 participants