@@ -195,35 +195,37 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
195
195
newArgs.push_back (generalizeComponentType (CanType (origArg)));
196
196
}
197
197
198
+ auto origSig = origSubs.getGenericSignature ();
199
+
198
200
// Generalize all of the conformances.
199
201
// TODO: for abstract requirements, we might not generalize all
200
202
// arguments, and we may need to leave corresponding conformances
201
203
// concrete.
202
204
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 ;
205
208
newConformances.push_back (
206
- ProtocolConformanceRef (origConformance.getRequirement ()));
209
+ ProtocolConformanceRef::forAbstract (req.getFirstType (),
210
+ req.getProtocolDecl ()));
207
211
}
208
212
209
- auto origSig = origSubs.getGenericSignature ();
210
213
auto newSubs = SubstitutionMap::get (origSig, newArgs, newConformances);
211
214
212
215
// Add any conformance requirements to the generic signature and
213
216
// 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});
227
229
}
228
230
229
231
// Build the new type.
0 commit comments