@@ -198,28 +198,40 @@ Type ProtocolConformanceRef::getAssociatedType(Type conformingType,
198
198
Type assocType) const {
199
199
if (isPack ()) {
200
200
auto *pack = getPack ();
201
- assert (conformingType->isEqual (pack->getType ()));
201
+ ASSERT (conformingType->isEqual (pack->getType ()));
202
202
return pack->getAssociatedType (assocType);
203
203
}
204
204
205
- assert (!isConcrete () || getConcrete ()->getType ()->isEqual (conformingType));
206
-
207
205
auto type = assocType->getCanonicalType ();
208
- auto proto = getRequirement ();
209
206
210
207
// Fast path for generic parameters.
211
- if (isa <GenericTypeParamType>(type)) {
212
- assert (type-> isEqual (proto-> getSelfInterfaceType ()) &&
208
+ if (auto paramTy = dyn_cast <GenericTypeParamType>(type)) {
209
+ ASSERT (paramTy-> getDepth () == 0 && paramTy-> getIndex () == 0 &&
213
210
" type parameter in protocol was not Self" );
214
211
return conformingType;
215
212
}
216
213
217
- // Fast path for dependent member types on 'Self' of our associated types.
218
- auto memberType = cast<DependentMemberType>(type);
219
- if (memberType.getBase ()->isEqual (proto->getSelfInterfaceType ()) &&
220
- memberType->getAssocType ()->getProtocol () == proto &&
221
- isConcrete ())
222
- return getConcrete ()->getTypeWitness (memberType->getAssocType ());
214
+ if (isInvalid ())
215
+ return ErrorType::get (assocType->getASTContext ());
216
+
217
+ auto proto = getRequirement ();
218
+
219
+ if (isConcrete ()) {
220
+ if (auto selfType = conformingType->getAs <DynamicSelfType>())
221
+ conformingType = selfType->getSelfType ();
222
+ ASSERT (getConcrete ()->getType ()->isEqual (conformingType));
223
+
224
+ // Fast path for dependent member types on 'Self' of our associated types.
225
+ auto memberType = cast<DependentMemberType>(type);
226
+ if (memberType.getBase ()->isEqual (proto->getSelfInterfaceType ()) &&
227
+ memberType->getAssocType ()->getProtocol () == proto) {
228
+ auto witnessType = getConcrete ()->getTypeWitness (
229
+ memberType->getAssocType ());
230
+ if (!witnessType)
231
+ return ErrorType::get (assocType->getASTContext ());
232
+ return witnessType;
233
+ }
234
+ }
223
235
224
236
// General case: consult the substitution map.
225
237
auto substMap =
0 commit comments