@@ -216,23 +216,36 @@ Type TypeResolution::resolveDependentMemberType(
216
216
return DependentMemberType::get (baseTy, assocType);
217
217
}
218
218
219
- // Otherwise, the nested type comes from a concrete type. Substitute the
220
- // base type into it.
219
+ // Otherwise, the nested type comes from a concrete type,
220
+ // or it's a typealias declared in protocol or protocol extension.
221
+ // Substitute the base type into it.
221
222
auto concrete = ref->getBoundDecl ();
222
223
auto lazyResolver = ctx.getLazyResolver ();
223
224
if (lazyResolver)
224
225
lazyResolver->resolveDeclSignature (concrete);
225
226
if (!concrete->hasInterfaceType ())
226
227
return ErrorType::get (ctx);
227
228
228
- if (concrete->getDeclContext ()->getSelfClassDecl ()) {
229
- // We found a member of a class from a protocol or protocol
230
- // extension.
231
- //
232
- // Get the superclass of the 'Self' type parameter.
233
- baseTy = (baseEquivClass->concreteType
234
- ? baseEquivClass->concreteType
235
- : baseEquivClass->superclass );
229
+ // Make sure that base type didn't get replaced along the way.
230
+ assert (baseTy->isTypeParameter ());
231
+
232
+ // There are two situations possible here:
233
+ //
234
+ // 1. Member comes from the protocol, which means that it has been
235
+ // found through a conformance constraint placed on base e.g. `T: P`.
236
+ // In this case member is a `typealias` declaration located in
237
+ // protocol or protocol extension.
238
+ //
239
+ // 2. Member comes from struct/enum/class type, which means that it
240
+ // has been found through same-type constraint on base e.g. `T == Q`.
241
+ //
242
+ // If this is situation #2 we need to make sure to switch base to
243
+ // a concrete type (according to equivalence class) otherwise we'd
244
+ // end up using incorrect generic signature while attempting to form
245
+ // a substituted type for the member we found.
246
+ if (!concrete->getDeclContext ()->getSelfProtocolDecl ()) {
247
+ baseTy = baseEquivClass->concreteType ? baseEquivClass->concreteType
248
+ : baseEquivClass->superclass ;
236
249
assert (baseTy);
237
250
}
238
251
0 commit comments