@@ -2082,6 +2082,8 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
2082
2082
ClassDecl *classDecl,
2083
2083
ConstructorDecl *superclassCtor,
2084
2084
DesignatedInitKind kind) {
2085
+ auto &ctx = tc.Context ;
2086
+
2085
2087
// FIXME: Inheriting initializers that have their own generic parameters
2086
2088
if (superclassCtor->getGenericParams ())
2087
2089
return nullptr ;
@@ -2098,54 +2100,35 @@ swift::createDesignatedInitOverride(TypeChecker &tc,
2098
2100
superclassCtor->getDeclContext ()
2099
2101
->getAsNominalTypeOrNominalTypeExtensionContext ();
2100
2102
Type superclassTy = classDecl->getSuperclass ();
2101
- Type superclassTyInContext = classDecl->mapTypeIntoContext (superclassTy);
2102
2103
NominalTypeDecl *superclassDecl = superclassTy->getAnyNominal ();
2103
2104
if (superclassCtorDecl != superclassDecl) {
2104
2105
return nullptr ;
2105
2106
}
2106
2107
2107
2108
// Determine the initializer parameters.
2108
- auto &ctx = tc.Context ;
2109
2109
2110
2110
// Create the 'self' declaration and patterns.
2111
2111
auto *selfDecl = ParamDecl::createSelf (SourceLoc (), classDecl);
2112
2112
2113
2113
// Create the initializer parameter patterns.
2114
2114
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
2115
2115
options |= ParameterList::Inherited;
2116
- auto *bodyParams = superclassCtor->getParameterList (1 )->clone (ctx,options);
2116
+ auto *bodyParams = superclassCtor->getParameterList (1 )->clone (ctx, options);
2117
2117
2118
2118
// If the superclass is generic, we need to map the superclass constructor's
2119
2119
// parameter types into the generic context of our class.
2120
2120
//
2121
2121
// We might have to apply substitutions, if for example we have a declaration
2122
2122
// 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));
2149
2132
}
2150
2133
2151
2134
// Create the initializer declaration, inheriting the name,
0 commit comments