@@ -2643,6 +2643,8 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
2643
2643
anyChanged = false ;
2644
2644
anyUnsubstituted = false ;
2645
2645
2646
+ LLVM_DEBUG (llvm::dbgs () << " Simplifying type witnesses -- iteration " << iterations << " \n " );
2647
+
2646
2648
if (++iterations > 100 ) {
2647
2649
llvm::errs () << " Too many iterations in simplifyCurrentTypeWitnesses()\n " ;
2648
2650
@@ -2678,6 +2680,10 @@ bool AssociatedTypeInference::simplifyCurrentTypeWitnesses() {
2678
2680
if (!typeWitness->hasTypeParameter ())
2679
2681
continue ;
2680
2682
2683
+ LLVM_DEBUG (llvm::dbgs () << " Attempting to simplify witness for "
2684
+ << assocType->getName ()
2685
+ << " : " << typeWitness << " \n " ;);
2686
+
2681
2687
auto simplified = typeWitness.transformRec (
2682
2688
[&](TypeBase *type) -> std::optional<Type> {
2683
2689
// Skip.
@@ -2806,10 +2812,16 @@ AssociatedTypeInference::getSubstOptionsWithCurrentTypeWitnesses() {
2806
2812
return nullptr ;
2807
2813
}
2808
2814
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 ;
2810
2822
if (type->hasTypeParameter ()) {
2811
2823
// Not fully substituted yet.
2812
- return ErrorType::get (type ->getASTContext ()).getPointer ();
2824
+ return ErrorType::get (thisProto ->getASTContext ()).getPointer ();
2813
2825
}
2814
2826
2815
2827
return type->mapTypeOutOfContext ().getPointer ();
0 commit comments