@@ -2042,36 +2042,6 @@ configureGenericDesignatedInitOverride(ASTContext &ctx,
2042
2042
newParams.push_back (newParam);
2043
2043
}
2044
2044
2045
- // Substitution map that maps the generic parameters of the superclass
2046
- // to the generic parameters of the derived class, and the generic
2047
- // parameters of the superclass initializer to the generic parameters
2048
- // of the derived class initializer.
2049
- auto *superclassSig = superclassCtor->getGenericSignature ();
2050
- if (superclassSig) {
2051
- unsigned superclassDepth = 0 ;
2052
- if (auto *genericSig = superclassDecl->getGenericSignature ())
2053
- superclassDepth = genericSig->getGenericParams ().back ()->getDepth () + 1 ;
2054
-
2055
- subMap = superclassSig->getSubstitutionMap (
2056
- [&](SubstitutableType *type) -> Type {
2057
- auto *gp = cast<GenericTypeParamType>(type);
2058
- if (gp->getDepth () < superclassDepth)
2059
- return Type (gp).subst (subMap);
2060
- return CanGenericTypeParamType::get (
2061
- gp->getDepth () - superclassDepth + depth,
2062
- gp->getIndex (),
2063
- ctx);
2064
- },
2065
- [&](CanType depTy, Type substTy, ProtocolType *protoType)
2066
- -> Optional<ProtocolConformanceRef> {
2067
- auto *proto = protoType->getDecl ();
2068
- if (auto conf = subMap.lookupConformance (depTy, proto))
2069
- return conf;
2070
-
2071
- return ProtocolConformanceRef (proto);
2072
- });
2073
- }
2074
-
2075
2045
// We don't have to clone the requirements, because they're not
2076
2046
// used for anything.
2077
2047
genericParams = GenericParamList::create (ctx,
@@ -2082,18 +2052,53 @@ configureGenericDesignatedInitOverride(ASTContext &ctx,
2082
2052
SourceLoc ());
2083
2053
genericParams->setOuterParameters (classDecl->getGenericParamsOfContext ());
2084
2054
2055
+ // Build a generic signature for the derived class initializer.
2085
2056
GenericSignatureBuilder builder (ctx);
2086
2057
builder.addGenericSignature (classDecl->getGenericSignature ());
2087
2058
2059
+ // Add the generic parameters.
2088
2060
for (auto *newParam : newParams)
2089
2061
builder.addGenericParameter (newParam);
2090
2062
2091
2063
auto source =
2092
2064
GenericSignatureBuilder::FloatingRequirementSource::forAbstract ();
2065
+ auto *superclassSig = superclassCtor->getGenericSignature ();
2066
+
2067
+ unsigned superclassDepth = 0 ;
2068
+ if (auto *genericSig = superclassDecl->getGenericSignature ())
2069
+ superclassDepth = genericSig->getGenericParams ().back ()->getDepth () + 1 ;
2070
+
2071
+ // We're going to be substituting the requirements of the base class
2072
+ // initializer to form the requirements of the derived class initializer.
2073
+ auto substFn = [&](SubstitutableType *type) -> Type {
2074
+ auto *gp = cast<GenericTypeParamType>(type);
2075
+ if (gp->getDepth () < superclassDepth)
2076
+ return Type (gp).subst (subMap);
2077
+ return CanGenericTypeParamType::get (
2078
+ gp->getDepth () - superclassDepth + depth,
2079
+ gp->getIndex (),
2080
+ ctx);
2081
+ };
2082
+
2083
+ auto lookupConformanceFn =
2084
+ [&](CanType depTy, Type substTy, ProtocolType *protoType)
2085
+ -> Optional<ProtocolConformanceRef> {
2086
+ auto *proto = protoType->getDecl ();
2087
+ if (!subMap.empty ())
2088
+ if (auto conf = subMap.lookupConformance (depTy, proto))
2089
+ return conf;
2090
+
2091
+ return ProtocolConformanceRef (proto);
2092
+ };
2093
+
2093
2094
for (auto reqt : superclassSig->getRequirements ())
2094
- if (auto substReqt = reqt.subst (subMap ))
2095
+ if (auto substReqt = reqt.subst (substFn, lookupConformanceFn ))
2095
2096
builder.addRequirement (*substReqt, source, nullptr );
2096
2097
2098
+ // Now form the substitution map that will be used to remap parameter
2099
+ // types.
2100
+ subMap = superclassSig->getSubstitutionMap (substFn, lookupConformanceFn);
2101
+
2097
2102
genericSig = std::move (builder).computeGenericSignature (SourceLoc ());
2098
2103
genericEnv = genericSig->createGenericEnvironment ();
2099
2104
} else {
0 commit comments