fix RepeatedFieldTest.Enumerator test #603
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
on my Windows machine RepeatedFieldTest.Enumerator is failing with error:
it looks like all changes to the enumerator variable in that test are immediately forgotten.
I eventually found the cause, which seems to be:
http://stackoverflow.com/questions/4642665/why-does-capturing-a-mutable-struct-variable-inside-a-closure-within-a-using-sta
and this bug report
https://connect.microsoft.com/VisualStudio/feedback/details/635745
Just removing the using block fixes the problem (as well are removing the lambda would), but it makes me wondering if we actually want RepeatedField.Enumerator to be a struct. Exposing enumerator struct makes as susceptible to subtle issues like these:
https://www.simple-talk.com/blogs/2010/05/19/why-enumerator-structs-are-a-really-bad-idea/
https://www.simple-talk.com/blogs/2010/05/20/why-enumerator-structs-are-a-really-bad-idea-redux/
(I think with Reset() method we are actually fine, because we don't implement IEnumerator.Reset() explicitly, unlike System.Collections.Generic.List, but I am wondering how much of a performance gain the struct-based enumerator actually is.
Switching the enumerator to private class might save us some headache in the future (MapField already has an enumerator class).