Skip to content

Commit 8606d3e

Browse files
committed
Sema: Simplify createDesignatedInitOverride()
1 parent 699977f commit 8606d3e

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
@@ -2082,6 +2082,8 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
20822082
ClassDecl *classDecl,
20832083
ConstructorDecl *superclassCtor,
20842084
DesignatedInitKind kind) {
2085+
auto &ctx = tc.Context;
2086+
20852087
// FIXME: Inheriting initializers that have their own generic parameters
20862088
if (superclassCtor->getGenericParams())
20872089
return nullptr;
@@ -2098,54 +2100,35 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
20982100
superclassCtor->getDeclContext()
20992101
->getAsNominalTypeOrNominalTypeExtensionContext();
21002102
Type superclassTy = classDecl->getSuperclass();
2101-
Type superclassTyInContext = classDecl->mapTypeIntoContext(superclassTy);
21022103
NominalTypeDecl *superclassDecl = superclassTy->getAnyNominal();
21032104
if (superclassCtorDecl != superclassDecl) {
21042105
return nullptr;
21052106
}
21062107

21072108
// Determine the initializer parameters.
2108-
auto &ctx = tc.Context;
21092109

21102110
// Create the 'self' declaration and patterns.
21112111
auto *selfDecl = ParamDecl::createSelf(SourceLoc(), classDecl);
21122112

21132113
// Create the initializer parameter patterns.
21142114
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
21152115
options |= ParameterList::Inherited;
2116-
auto *bodyParams = superclassCtor->getParameterList(1)->clone(ctx,options);
2116+
auto *bodyParams = superclassCtor->getParameterList(1)->clone(ctx, options);
21172117

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

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

0 commit comments

Comments
 (0)