I'm confused about subtyping (lack of one) in meta types of protocol existentials.
Consider, the following example:
class C {}
class D: C {}
let c: C = D()
let cType: C.Type = D.self // OK
protocol P {}
protocol Q: P {}
struct S: Q {}
let q: Q = S() // OK. S seems to be a subtype of existential for Q.
let qType: Q.Protocol = S.self // error: cannot convert value of type 'S.Type' to specified type 'Q.Protocol'
let p: P = q // OK. Existential for Q seems to be a subtype of existential for P.
let pType: P.Protocol = Q.self // error: cannot convert value of type 'Q.Protocol' to specified type 'P.Protocol'
My intuitive understanding of subtyping is relation is that if you can write
let x: A = ...
let y: B = x
then A
is a subtype of B
.
And subtyping of types is related to subtyping of meta-types: if A
is a subtype of B
, then A.Type
is also a subtype of B.Type
.
Is my understanding correct? Is there a more formal definition?
And I'm confused, because from that logic if follows that S.Type
should be a subtype of Q.Protocol
, which in turn should be a subtype of P.Protocol
. But currently that's not the case.