Skip to content

CachingIterator: do not ask when not in valid state - #230

Merged
dg merged 21 commits into
nette:masterfrom
hrach:caching-iterator-check-validity
Sep 30, 2020
Merged

CachingIterator: do not ask when not in valid state#230
dg merged 21 commits into
nette:masterfrom
hrach:caching-iterator-check-validity

Conversation

@hrach

@hrach hrach commented Sep 6, 2020

Copy link
Copy Markdown
Contributor
  • bug fix: yes
  • BC break: no, but...
  • doc PR: no

The inner iterator is one iteration ahead and therefore when CachingIterator asks for the next value (key), it uses a current() method on the inner iterator. But the iteration may have finished and calling iterator's current() and key() in invalid state may produce an exception or invalid data.

PHP'S internal ArrayIterator returns a null, but generally speaking the iterators should rather throw. When doing types properly, we can't even type such interface.

This PR asks first if the inner iterator is in a valid state.

@hrach

hrach commented Sep 6, 2020

Copy link
Copy Markdown
Contributor Author

Test failures seems unrelated.

@dg
dg force-pushed the master branch 4 times, most recently from 63d6779 to 31553c2 Compare September 29, 2020 13:23
@hrach

hrach commented Sep 29, 2020

Copy link
Copy Markdown
Contributor Author

@dg what do you think?

@dg
dg force-pushed the master branch 4 times, most recently from f6d1b05 to 2a1d768 Compare September 29, 2020 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants