@@ -2643,6 +2643,8 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
26432643 anyChanged = false ;
26442644 anyUnsubstituted = false ;
26452645
2646+ LLVM_DEBUG (llvm::dbgs () << " Simplifying type witnesses -- iteration " << iterations << " \n " );
2647+
26462648 if (++iterations > 100 ) {
26472649 llvm::errs () << " Too many iterations in simplifyCurrentTypeWitnesses()\n " ;
26482650
@@ -2678,6 +2680,10 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
26782680 if (!typeWitness->hasTypeParameter ())
26792681 continue ;
26802682
2683+ LLVM_DEBUG (llvm::dbgs () << " Attempting to simplify witness for "
2684+ << assocType->getName ()
2685+ << " : " << typeWitness << " \n " ;);
2686+
26812687 auto simplified = typeWitness.transformRec (
26822688 [&](TypeBase *type) -> std::optional<Type> {
26832689 // Skip.
@@ -2806,10 +2812,16 @@ AssociatedTypeInference::getSubstOptionsWithCurrentTypeWitnesses() {
28062812 return nullptr ;
28072813 }
28082814
2809- Type type = self->typeWitnesses .begin (assocType)->first ;
2815+ auto found = self->typeWitnesses .begin (assocType);
2816+ if (found == self->typeWitnesses .end ()) {
2817+ // Invalid code.
2818+ return ErrorType::get (thisProto->getASTContext ()).getPointer ();
2819+ }
2820+
2821+ Type type = found->first ;
28102822 if (type->hasTypeParameter ()) {
28112823 // Not fully substituted yet.
2812- return ErrorType::get (type ->getASTContext ()).getPointer ();
2824+ return ErrorType::get (thisProto ->getASTContext ()).getPointer ();
28132825 }
28142826
28152827 return type->mapTypeOutOfContext ().getPointer ();
0 commit comments