Open jcouv opened 1 week ago
@jcouv why did you put this in Backlog?
@jaredpar My reasoning was: this is an old problem, it is only observable if you enumerate the same enumerator multiple times, and nobody reported it. So the impact seems limited.
The spec states that we should set state of the enumerator object to after in various scenarios:
yield break
is encounteredDispose
causes an exception to be thrownIt is possible to observe whether the state was properly set to after by checking whether
GetEnumerator()
re-uses the current state machine instance or allocates a new one.In the scenarios above, enumerators don't properly set the state to after.
The impact is not too significant as we're making a change to ensure that
Dispose()
does set the state to after in non-exceptional cases, and this is only affecting an optimization. So in most normal usages (ie. where the enumerator is only used once or where it is disposed without exception thrown before we callGetEnumerator()
again) the behavior is fine.Note: this issue is referenced in tests. It also affects VB