-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Generics Manifesto] Existential subtyping as generic constraint #33552
base: main
Are you sure you want to change the base?
[Generics Manifesto] Existential subtyping as generic constraint #33552
Conversation
…ntial subtyping as an important custom case
|
I’m still confused about what this clarification is trying to accomplish. It seems like you want the ability for certain protocols to conform to themselves. That in hand, you don’t need a new kind of constraint here. Seeing |
|
Currently Consider the following example: protocol P {}
struct S: P {}
let x: S = S()
let y: P = S()
func f(_ a: P) {}
f(x) // OK
f(y) // OK
func g<T: ???>(_ a: T) { f(a) }Types Let's ask ourselves how types I'm stating that this relationship is a subtyping. Every type is a subtype of itself. So type So, for the Next, I'm making an observation that there is already a subtyping constraint in the language. If I have So we already have:
That means that If there is an ambiguity, I'm suggesting Note that in many places, there is no such ambiguity. For example, in The syntax of
I think it popped up in the discussion of eliminating extension (any Hashable): Hashable {
...
}But using |
|
Also, note that if protocol has static members, Small summary:
|
Updated 'Generalized supertype constraints' section of GenericsManifest based on https://forums.swift.org/t/existential-subtyping-as-generic-constraint/31584.
I think this addresses an important pain point when using protocols and generics together. Maybe this even should be separated from 'Generalized supertype constraints' and placed in 'Removing unnecessary restrictions' section, rather than 'Minor extensions' section.
Note: This is a copy from #28741, because GitHub does not allow to edit source branch of the pull-request.