silverstripe/silverstripe-framework — pull request #2287 by miiihi (2013-08-02 12:57:32+00:00)
Title: BUGFIX: setting currentIndex when going Up causes wrong scope.

When using Up in a loop opened with Up.Var is setting currentIndex wrong.
Without it, scopes work as expected.

Test case

```
example_controller.php:
...
public function loopA() {
return new ArrayList(array(
new ArrayData(array(
'myVal'	=> 'A.A',
)),
new ArrayData(array(
'myVal'	=> 'A.B',
))
));
}
public function loopB() {
return new ArrayList(array(
new ArrayData(array(
'myVal'	=> 'B.A',
)),
new ArrayData(array(
'myVal'	=> 'B.B',
))
));
}
public function myVal() {
return 'zero';
}
...
```

```
example_template.ss
...

<% loop loopA %>
myVal: $myVal
<% loop Up.loopB %>
myVal: $myVal Up myVal: $Up.myVal
<% end_loop %>
<% end_loop %>

...
```

```
Expected output of template:
myVal: A.A
myVal: B.A Up myVal: A.A
myVal: B.B Up myVal: A.A

myVal: A.B
myVal: B.A Up myVal: A.B
myVal: B.B Up myVal: A.B

Actual output of template:
myVal: A.A
myVal: B.A Up myVal: zero
myVal: B.B Up myVal: zero

myVal: A.B
myVal: B.A Up myVal: zero
myVal: B.B Up myVal: zero
```

Fix is quick and not tested enough... but it solves the above problem.
SSViewer_Scope stack logic and stack indexes are pretty complex and poorly documented in the code, which makes this fix a bit problematic...
Anyway, at least bug is obvious and repeatable.