@@ -2644,6 +2644,8 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
26442644 anyChanged = false ;
26452645 anyUnsubstituted = false ;
26462646
2647+ LLVM_DEBUG (llvm::dbgs () << " Simplifying type witnesses -- iteration " << iterations << " \n " );
2648+
26472649 if (++iterations > 100 ) {
26482650 llvm::errs () << " Too many iterations in simplifyCurrentTypeWitnesses()\n " ;
26492651
@@ -2679,6 +2681,10 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
26792681 if (!typeWitness->hasTypeParameter ())
26802682 continue ;
26812683
2684+ LLVM_DEBUG (llvm::dbgs () << " Attempting to simplify witness for "
2685+ << assocType->getName ()
2686+ << " : " << typeWitness << " \n " ;);
2687+
26822688 auto simplified = typeWitness.transformRec (
26832689 [&](TypeBase *type) -> std::optional<Type> {
26842690 // Skip.
@@ -2807,10 +2813,16 @@ AssociatedTypeInference::getSubstOptionsWithCurrentTypeWitnesses() {
28072813 return nullptr ;
28082814 }
28092815
2810- Type type = self->typeWitnesses .begin (assocType)->first ;
2816+ auto found = self->typeWitnesses .begin (assocType);
2817+ if (found == self->typeWitnesses .end ()) {
2818+ // Invalid code.
2819+ return ErrorType::get (thisProto->getASTContext ()).getPointer ();
2820+ }
2821+
2822+ Type type = found->first ;
28112823 if (type->hasTypeParameter ()) {
28122824 // Not fully substituted yet.
2813- return ErrorType::get (type ->getASTContext ()).getPointer ();
2825+ return ErrorType::get (thisProto ->getASTContext ()).getPointer ();
28142826 }
28152827
28162828 return type->mapTypeOutOfContext ().getPointer ();
0 commit comments