@@ -2088,6 +2088,8 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
2088
2088
ClassDecl *classDecl,
2089
2089
ConstructorDecl *superclassCtor,
2090
2090
DesignatedInitKind kind) {
2091
+ auto &ctx = tc.Context ;
2092
+
2091
2093
// FIXME: Inheriting initializers that have their own generic parameters
2092
2094
if (superclassCtor->getGenericParams ())
2093
2095
return nullptr ;
@@ -2104,54 +2106,35 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
2104
2106
superclassCtor->getDeclContext ()
2105
2107
->getAsNominalTypeOrNominalTypeExtensionContext ();
2106
2108
Type superclassTy = classDecl->getSuperclass ();
2107
- Type superclassTyInContext = classDecl->mapTypeIntoContext (superclassTy);
2108
2109
NominalTypeDecl *superclassDecl = superclassTy->getAnyNominal ();
2109
2110
if (superclassCtorDecl != superclassDecl) {
2110
2111
return nullptr ;
2111
2112
}
2112
2113
2113
2114
// Determine the initializer parameters.
2114
- auto &ctx = tc.Context ;
2115
2115
2116
2116
// Create the 'self' declaration and patterns.
2117
2117
auto *selfDecl = ParamDecl::createSelf (SourceLoc (), classDecl);
2118
2118
2119
2119
// Create the initializer parameter patterns.
2120
2120
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
2121
2121
options |= ParameterList::Inherited;
2122
- auto *bodyParams = superclassCtor->getParameterList (1 )->clone (ctx,options);
2122
+ auto *bodyParams = superclassCtor->getParameterList (1 )->clone (ctx, options);
2123
2123
2124
2124
// If the superclass is generic, we need to map the superclass constructor's
2125
2125
// parameter types into the generic context of our class.
2126
2126
//
2127
2127
// We might have to apply substitutions, if for example we have a declaration
2128
2128
// 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));
2155
2138
}
2156
2139
2157
2140
// Create the initializer declaration, inheriting the name,
0 commit comments