Sema: Fixes for conformance between higher-kind metatypes

For a concrete type A and protocol type P, A <c P now implies
A.Type <c P.Type, not just A.Type < P.Type. This in turn means
that A.Type.Type <c P.Type.Type. To make the coercion work,
recursively peel off metatype layers when collecting conformances
and in a similar situation in IRGen.

Swift SVN r29377
This commit is contained in:
Slava Pestov
2015-06-15 02:00:47 +00:00
parent 6a9790ed30
commit 1052d095c4
4 changed files with 34 additions and 8 deletions

View File

@@ -1972,10 +1972,11 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
}
}
// A subtyping relation between a metatype and an existential
// metatype is actually equivalent to a conformance relationship
// on the instance types.
if (concrete && kind >= TypeMatchKind::Subtype) {
// Conformance of a metatype to an existential metatype is actually
// equivalent to a conformance relationship on the instance types.
// This applies to nested metatype levels, so if A : P then
// A.Type : P.Type.
if (concrete && kind >= TypeMatchKind::ConformsTo) {
if (auto meta1 = type1->getAs<MetatypeType>()) {
if (auto meta2 = type2->getAs<ExistentialMetatypeType>()) {
return matchTypes(meta1->getInstanceType(),