Skip to content

Commit 1f3b5a4

Browse files
committed
Sema: Simplify createDesignatedInitOverride()
1 parent efe2a74 commit 1f3b5a4

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,8 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
20882088
ClassDecl *classDecl,
20892089
ConstructorDecl *superclassCtor,
20902090
DesignatedInitKind kind) {
2091+
auto &ctx = tc.Context;
2092+
20912093
// FIXME: Inheriting initializers that have their own generic parameters
20922094
if (superclassCtor->getGenericParams())
20932095
return nullptr;
@@ -2104,54 +2106,35 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
21042106
superclassCtor->getDeclContext()
21052107
->getAsNominalTypeOrNominalTypeExtensionContext();
21062108
Type superclassTy = classDecl->getSuperclass();
2107-
Type superclassTyInContext = classDecl->mapTypeIntoContext(superclassTy);
21082109
NominalTypeDecl *superclassDecl = superclassTy->getAnyNominal();
21092110
if (superclassCtorDecl != superclassDecl) {
21102111
return nullptr;
21112112
}
21122113

21132114
// Determine the initializer parameters.
2114-
auto &ctx = tc.Context;
21152115

21162116
// Create the 'self' declaration and patterns.
21172117
auto *selfDecl = ParamDecl::createSelf(SourceLoc(), classDecl);
21182118

21192119
// Create the initializer parameter patterns.
21202120
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
21212121
options |= ParameterList::Inherited;
2122-
auto *bodyParams = superclassCtor->getParameterList(1)->clone(ctx,options);
2122+
auto *bodyParams = superclassCtor->getParameterList(1)->clone(ctx, options);
21232123

21242124
// If the superclass is generic, we need to map the superclass constructor's
21252125
// parameter types into the generic context of our class.
21262126
//
21272127
// We might have to apply substitutions, if for example we have a declaration
21282128
// like 'class A : B<Int>'.
2129-
if (superclassDecl->getGenericSignatureOfContext()) {
2130-
auto *moduleDecl = classDecl->getParentModule();
2131-
auto subMap = superclassTyInContext->getContextSubstitutionMap(
2132-
moduleDecl,
2133-
superclassDecl,
2134-
classDecl->getGenericEnvironment());
2135-
2136-
for (auto *decl : *bodyParams) {
2137-
auto paramTy = decl->getInterfaceType()->getInOutObjectType();
2138-
2139-
// Apply the superclass substitutions to produce a contextual
2140-
// type in terms of the derived class archetypes.
2141-
auto paramSubstTy = paramTy.subst(subMap);
2142-
decl->setType(paramSubstTy);
2143-
2144-
// Map it to an interface type in terms of the derived class
2145-
// generic signature.
2146-
decl->setInterfaceType(paramSubstTy->mapTypeOutOfContext());
2147-
}
2148-
} else {
2149-
for (auto *decl : *bodyParams) {
2150-
if (!decl->hasType())
2151-
decl->setType(
2152-
classDecl->mapTypeIntoContext(
2153-
decl->getInterfaceType()->getInOutObjectType()));
2154-
}
2129+
auto *moduleDecl = classDecl->getParentModule();
2130+
auto subMap = superclassTy->getContextSubstitutionMap(
2131+
moduleDecl, superclassDecl);
2132+
2133+
for (auto *decl : *bodyParams) {
2134+
auto paramTy = decl->getInterfaceType();
2135+
auto substTy = paramTy.subst(subMap);
2136+
decl->setInterfaceType(substTy);
2137+
decl->setType(classDecl->mapTypeIntoContext(substTy));
21552138
}
21562139

21572140
// Create the initializer declaration, inheriting the name,

0 commit comments

Comments
 (0)