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