@@ -198,28 +198,40 @@ Type ProtocolConformanceRef::getAssociatedType(Type conformingType,
198198 Type assocType) const {
199199 if (isPack ()) {
200200 auto *pack = getPack ();
201- assert (conformingType->isEqual (pack->getType ()));
201+ ASSERT (conformingType->isEqual (pack->getType ()));
202202 return pack->getAssociatedType (assocType);
203203 }
204204
205- assert (!isConcrete () || getConcrete ()->getType ()->isEqual (conformingType));
206-
207205 auto type = assocType->getCanonicalType ();
208- auto proto = getRequirement ();
209206
210207 // 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 &&
213210 " type parameter in protocol was not Self" );
214211 return conformingType;
215212 }
216213
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+ }
223235
224236 // General case: consult the substitution map.
225237 auto substMap =
0 commit comments