@@ -195,35 +195,37 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
195195 newArgs.push_back (generalizeComponentType (CanType (origArg)));
196196 }
197197
198+ auto origSig = origSubs.getGenericSignature ();
199+
198200 // Generalize all of the conformances.
199201 // TODO: for abstract requirements, we might not generalize all
200202 // arguments, and we may need to leave corresponding conformances
201203 // concrete.
202204 SmallVector<ProtocolConformanceRef, 4 > newConformances;
203- auto origConformances = origSubs.getConformances ();
204- for (auto origConformance: origConformances) {
205+ for (const auto &req : origSig.getRequirements ()) {
206+ if (req.getKind () != RequirementKind::Conformance)
207+ continue ;
205208 newConformances.push_back (
206- ProtocolConformanceRef (origConformance.getRequirement ()));
209+ ProtocolConformanceRef::forAbstract (req.getFirstType (),
210+ req.getProtocolDecl ()));
207211 }
208212
209- auto origSig = origSubs.getGenericSignature ();
210213 auto newSubs = SubstitutionMap::get (origSig, newArgs, newConformances);
211214
212215 // Add any conformance requirements to the generic signature and
213216 // remember the conformances we generalized.
214- if (!origConformances.empty ()) {
215- size_t i = 0 ;
216- for (auto &origReq: origSig.getRequirements ()) {
217- if (origReq.getKind () != RequirementKind::Conformance) continue ;
218- auto origConformance = origConformances[i++];
219-
220- auto newReq = origReq.subst (newSubs);
221- addedRequirements.push_back (newReq);
222-
223- substConformances.insert ({{newReq.getFirstType ()->getCanonicalType (),
224- newReq.getProtocolDecl ()},
225- origConformance});
226- }
217+ auto origConformances = origSubs.getConformances ();
218+ size_t i = 0 ;
219+ for (auto &origReq: origSig.getRequirements ()) {
220+ if (origReq.getKind () != RequirementKind::Conformance) continue ;
221+ auto origConformance = origConformances[i++];
222+
223+ auto newReq = origReq.subst (newSubs);
224+ addedRequirements.push_back (newReq);
225+
226+ substConformances.insert ({{newReq.getFirstType ()->getCanonicalType (),
227+ newReq.getProtocolDecl ()},
228+ origConformance});
227229 }
228230
229231 // Build the new type.
0 commit comments