@@ -231,35 +231,44 @@ Optional<Type> ConcreteContraction::substTypeParameter(
231
231
if (!substBaseType)
232
232
return None;
233
233
234
- auto *decl = (*substBaseType)->getAnyNominal ();
235
- if (decl == nullptr ) {
236
- if (Debug) {
237
- llvm::dbgs () << " @@@ Not a nominal type: " << *substBaseType << " \n " ;
238
- }
239
-
240
- return None;
241
- }
242
-
243
- auto *module = decl->getParentModule ();
244
-
245
234
// A resolved DependentMemberType stores an associated type declaration.
246
235
//
247
236
// Handle this by looking up the corresponding type witness in the base
248
237
// type's conformance to the associated type's protocol.
249
238
if (auto *assocType = memberType->getAssocType ()) {
250
- auto conformance = module ->lookupConformance (
251
- *substBaseType, assocType->getProtocol ());
239
+ auto *proto = assocType->getProtocol ();
240
+ auto *module = proto->getParentModule ();
241
+
242
+ auto conformance = ((*substBaseType)->isTypeParameter ()
243
+ ? ProtocolConformanceRef (proto)
244
+ : module ->lookupConformance (*substBaseType, proto));
252
245
253
246
// The base type doesn't conform, in which case the requirement remains
254
247
// unsubstituted.
255
- if (!conformance)
248
+ if (!conformance) {
249
+ if (Debug) {
250
+ llvm::dbgs () << " @@@ " << substBaseType << " does not conform to "
251
+ << proto->getName () << " \n " ;
252
+ }
256
253
return None;
254
+ }
257
255
258
256
return assocType->getDeclaredInterfaceType ()
259
257
->castTo <DependentMemberType>()
260
258
->substBaseType (module , *substBaseType);
261
259
}
262
260
261
+ auto *decl = (*substBaseType)->getAnyNominal ();
262
+ if (decl == nullptr ) {
263
+ if (Debug) {
264
+ llvm::dbgs () << " @@@ Not a nominal type: " << *substBaseType << " \n " ;
265
+ }
266
+
267
+ return None;
268
+ }
269
+
270
+ auto *module = decl->getParentModule ();
271
+
263
272
// An unresolved DependentMemberType stores an identifier. Handle this
264
273
// by performing a name lookup into the base type.
265
274
auto *typeDecl = lookupConcreteNestedType (module , decl,
0 commit comments