Sema: Remove redundant mapType{Into,OutOf}Context() calls

The code in recordTypeWitness() seemed to be completely bogus;
it already receives a type written in terms of the archetypes
of the adoptee's context, so mapTypeOutOfContext() did nothing
here, because it was using the wrong substitutions.

The logic for synthesizing designated initializers was also
slightly wrong if the class was nested inside a generic
function.

Finally, interface and contextual types of a derived rawValue
were flipped around.
This commit is contained in:
Slava Pestov
2016-06-25 05:41:03 -07:00
parent 584eda38ed
commit 68dc9455e7
6 changed files with 29 additions and 33 deletions

View File

@@ -2060,15 +2060,17 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
return nullptr;
// Lookup will sometimes give us initializers that are from the ancestors of
// our immediate superclass. So, from the superclass constructor, we look
// one level up to the enclosing type context which will either be a class
// our immediate superclass. So, from the superclass constructor, we look
// one level up to the enclosing type context which will either be a class
// or an extension. We can use the type declared in that context to check
// if it's our immediate superclass and give up if we didn't.
//
//
// FIXME: Remove this when lookup of initializers becomes restricted to our
// immediate superclass.
Type superclassTyInCtor = superclassCtor->getDeclContext()->getDeclaredTypeInContext();
Type superclassTyInCtor = superclassCtor->getDeclContext()->getDeclaredTypeOfContext();
Type superclassTy = classDecl->getSuperclass();
Type superclassTyInContext = ArchetypeBuilder::mapTypeIntoContext(
classDecl, superclassTy);
NominalTypeDecl *superclassDecl = superclassTy->getAnyNominal();
if (superclassTyInCtor->getAnyNominal() != superclassDecl) {
return nullptr;
@@ -2093,7 +2095,7 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
if (superclassDecl->isGenericContext()) {
if (auto *superclassSig = superclassDecl->getGenericSignatureOfContext()) {
auto *moduleDecl = classDecl->getParentModule();
auto subs = superclassTy->gatherAllSubstitutions(
auto subs = superclassTyInContext->gatherAllSubstitutions(
moduleDecl, nullptr, nullptr);
auto subsMap = superclassSig->getSubstitutionMap(subs);
@@ -2103,13 +2105,14 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
auto paramTy = ArchetypeBuilder::mapTypeOutOfContext(
superclassDecl, decl->getType());
// Apply the superclass substitutions to produce an interface
// type in terms of the class generic signature.
// Apply the superclass substitutions to produce a contextual
// type in terms of the derived class archetypes.
auto paramSubstTy = paramTy.subst(moduleDecl, subsMap, SubstOptions());
decl->setInterfaceType(paramSubstTy);
decl->overwriteType(paramSubstTy);
// Map it to a contextual type in terms of the class's archetypes.
decl->overwriteType(ArchetypeBuilder::mapTypeIntoContext(
// Map it to an interface type in terms of the derived class
// generic signature.
decl->setInterfaceType(ArchetypeBuilder::mapTypeOutOfContext(
classDecl, paramSubstTy));
}
}