@@ -160,7 +160,7 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type, Identifier name) const {
160160 if (!assocType)
161161 return ErrorType::get (proto->getASTContext ());
162162
163- return getTypeWitness (type, assocType);
163+ return getTypeWitness (assocType);
164164}
165165
166166ConcreteDeclRef
@@ -190,43 +190,32 @@ ProtocolConformanceRef::getConditionalRequirements() const {
190190 return {};
191191}
192192
193- Type ProtocolConformanceRef::getTypeWitness (Type conformingType,
194- AssociatedTypeDecl *assocType,
193+ Type ProtocolConformanceRef::getTypeWitness (AssociatedTypeDecl *assocType,
195194 SubstOptions options) const {
195+ if (isInvalid ())
196+ return ErrorType::get (assocType->getASTContext ());
197+
196198 if (isPack ()) {
197199 auto *pack = getPack ();
198- ASSERT (conformingType->isEqual (pack->getType ()));
199- return pack->getTypeWitness (assocType);
200+ return pack->getTypeWitness (assocType, options);
200201 }
201202
202- auto failed = [&]() {
203- return DependentMemberType::get (ErrorType::get (conformingType),
204- assocType);
205- };
206-
207- if (isInvalid ())
208- return failed ();
209-
210- auto proto = getProtocol ();
211- ASSERT (assocType->getProtocol () == proto);
212-
213203 if (isConcrete ()) {
214- auto witnessType = getConcrete ()->getTypeWitness (assocType, options);
215- if (!witnessType || witnessType->is <ErrorType>())
216- return failed ();
204+ auto *concrete = getConcrete ();
205+ ASSERT (concrete->getProtocol () == assocType->getProtocol ());
206+
207+ auto witnessType = concrete->getTypeWitness (assocType, options);
208+ if (!witnessType)
209+ return ErrorType::get (assocType->getASTContext ());
217210 return witnessType;
218211 }
219212
220- ASSERT (isAbstract ());
213+ auto *abstract = getAbstract ();
214+ auto conformingType = abstract->getType ();
215+ ASSERT (abstract->getProtocol () == assocType->getProtocol ());
221216
222- if (auto *archetypeType = conformingType->getAs <ArchetypeType>()) {
217+ if (auto *archetypeType = conformingType->getAs <ArchetypeType>())
223218 return archetypeType->getNestedType (assocType);
224- }
225-
226- CONDITIONAL_ASSERT (conformingType->isTypeParameter () ||
227- conformingType->isTypeVariableOrMember () ||
228- conformingType->is <UnresolvedType>() ||
229- conformingType->is <PlaceholderType>());
230219
231220 return DependentMemberType::get (conformingType, assocType);
232221}
0 commit comments