@@ -5434,6 +5434,8 @@ class BindingProducer {
5434
5434
// / for type variables found at one level, before proceeding to
5435
5435
// / supertypes or literal defaults etc.
5436
5436
virtual bool needsToComputeNext () const = 0;
5437
+
5438
+ virtual bool isExhausted () const = 0;
5437
5439
};
5438
5440
5439
5441
class TypeVarBindingProducer : public BindingProducer <TypeVariableBinding> {
@@ -5460,6 +5462,8 @@ class TypeVarBindingProducer : public BindingProducer<TypeVariableBinding> {
5460
5462
// / to that protocol or be wrapped in an optional.
5461
5463
bool CanBeNil;
5462
5464
5465
+ bool IsExhausted = false ;
5466
+
5463
5467
public:
5464
5468
using Element = TypeVariableBinding;
5465
5469
@@ -5469,11 +5473,16 @@ class TypeVarBindingProducer : public BindingProducer<TypeVariableBinding> {
5469
5473
ArrayRef<Binding> getCurrentBindings () const { return Bindings; }
5470
5474
5471
5475
Optional<Element> operator ()() override {
5476
+ if (isExhausted ())
5477
+ return None;
5478
+
5472
5479
// Once we reach the end of the current bindings
5473
5480
// let's try to compute new ones, e.g. supertypes,
5474
5481
// literal defaults, if that fails, we are done.
5475
- if (needsToComputeNext () && !computeNext ())
5482
+ if (needsToComputeNext () && !computeNext ()) {
5483
+ IsExhausted = true ;
5476
5484
return None;
5485
+ }
5477
5486
5478
5487
auto &binding = Bindings[Index++];
5479
5488
@@ -5492,7 +5501,11 @@ class TypeVarBindingProducer : public BindingProducer<TypeVariableBinding> {
5492
5501
return TypeVariableBinding (TypeVar, binding);
5493
5502
}
5494
5503
5495
- bool needsToComputeNext () const override { return Index >= Bindings.size (); }
5504
+ bool needsToComputeNext () const override {
5505
+ return isExhausted () ? false : Index >= Bindings.size ();
5506
+ }
5507
+
5508
+ bool isExhausted () const override { return IsExhausted; }
5496
5509
5497
5510
private:
5498
5511
// / Compute next batch of bindings if possible, this could
@@ -5565,10 +5578,10 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
5565
5578
}
5566
5579
5567
5580
Optional<Element> operator ()() override {
5568
- unsigned currIndex = Index;
5569
- if (currIndex >= Choices.size ())
5581
+ if (isExhausted ())
5570
5582
return None;
5571
5583
5584
+ unsigned currIndex = Index;
5572
5585
bool isBeginningOfPartition = PartitionIndex < PartitionBeginning.size () &&
5573
5586
PartitionBeginning[PartitionIndex] == Index;
5574
5587
if (isBeginningOfPartition)
@@ -5594,6 +5607,8 @@ class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
5594
5607
5595
5608
bool needsToComputeNext () const override { return false ; }
5596
5609
5610
+ bool isExhausted () const override { return Index >= Choices.size (); }
5611
+
5597
5612
private:
5598
5613
// Partition the choices in the disjunction into groups that we will
5599
5614
// iterate over in an order appropriate to attempt to stop before we
0 commit comments