I think this makes the situation much more complex that it really should be. As I mentioned previously in this thread, the "true" P.Type
kinda already exists, but it's not obtainable or properly expressible. This metatype fix via the any
keyword allows us to also fill this hole.
protocol P {}
func whatAmI<T>(_ t: T.Type) {
print(type(of: t))
}
whatAmI(P.Type.self) // P.Type.Protocol
^~~~~~
Make a breaking change, and let P.self
actually return that P.Type
instead while shift the previous P.Protocol
to be the result of (any P).self
and re-brand it as (any P).Type
. Done.
People are constantly reaching out for P.Type
but get (any P).Type
instead because of all this metatype fusion madness. This is the right time to fix this, and I disagree that it's orthogonal to this proposal. Having the ability to actually get the singleton metatype P.Type
would fix sooo many issues and confusion in the swift community.
This one extra thing unlocks an entire new set of generic algorithms. We can either ignore that or push this forward while we're already changing the status quo here. I've earned a lot of disagreement in this thread, just to see the core team join the conversation and make things clear to actually include the changes I've been fighting for the whole time.
P.S.: If you have Swift compiler know-hows, implement a quick and dirty proof-of-concept of this and see how awesome the expressiveness of the language becomes. It's a win win situation.