Merge: Fix bug with reverse iterators in arrays
authorJean Privat <jean@pryen.org>
Thu, 16 Jul 2015 15:35:41 +0000 (11:35 -0400)
committerJean Privat <jean@pryen.org>
Thu, 16 Jul 2015 15:35:41 +0000 (11:35 -0400)
commit23e3bf51109cfe79ebb9dadf97c35791e53aeeba
treeb93946ea6e20350eb068acd2c5480868e811fb2c
parent95792f75eb7bd17bb1c7287bc62bf96735550df6
parent3a3a6dbf89c0163f74dbbbb72fd376e2369eae3c
Merge: Fix bug with reverse iterators in arrays

Using `Array::iterator` after a finished `reverse_iterator` iterates only on the first element, or crash if array is empty. As `ReverseArrayIterator` specialize `ArrayIterator`, it can cache itself in the array to be used by `iterator`.

This PR simply disable caching for reverse iterators. We could add a distinct cache for the reverse iterator if we need the performance.

This minimal program highlights the bug:
~~~nit
var a = [1, 2, 3]
for x in a.reverse_iterator do print x
print "-"
for x in a.iterator do print x
~~~

Output:
~~~
3
2
1
-
1
~~~

Pull-Request: #1569
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>