stanislaw89 opened a new issue #165:
URL: https://github.com/apache/royale-compiler/issues/165
Test case:
```
package {
import mx.collections.ArrayCollection;
import org.apache.royale.test.Assert;
public class WeirdArrayCollectionBugTest {
[Test]
public function working():void {
var wrapper:SomeWrapper = createWrapper();
var arr:Array = [];
var collection:ArrayCollection = wrapper.items;
for each(var item:SomeItem in collection) {
arr.push(item);
trace(item);
}
Assert.assertEquals(2, arr.length);
Assert.assertEquals("a", arr[0].name);
Assert.assertEquals("b", arr[1].name);
}
[Test]
public function bug():void {
var wrapper:SomeWrapper = createWrapper();
var arr:Array = [];
for each(var item:SomeItem in wrapper.items) {
arr.push(item);
trace(item);
}
Assert.assertEquals(2, arr.length);
Assert.assertEquals("a", arr[0].name);
Assert.assertEquals("b", arr[1].name);
}
private static function createWrapper():SomeWrapper {
return new SomeWrapper(new ArrayCollection([new SomeItem("a"), new
SomeItem("b")]));
}
}
}
import mx.collections.ArrayCollection;
class SomeWrapper {
public var items:ArrayCollection;
public function SomeWrapper(items:ArrayCollection) {
this.items = items;
}
}
class SomeItem {
public var name:String;
public function SomeItem(name:String) {
this.name = name;
}
}
```
The first "working()" test works fine but the "bug" test fails with this
output
```
WeirdArrayCollectionBugTest.bug .
2Language.as:254 undefined
Language.as:254 WeirdArrayCollectionBugTest.bug E
Language.as:254 Time: 0.025
Language.as:254 There was 1 failure:
Language.as:254 1 WeirdArrayCollectionBugTest.bug Cannot read property
'name' of undefined
```
The only difference is
```
var collection:ArrayCollection = wrapper.items;
for each(var item:SomeItem in collection) {
```
vs
```
for each(var item:SomeItem in wrapper.items) {
```
For some reason
`for each(var item:SomeItem in wrapper.items) {`
generates JavaScript
`var item = foreachiter1_target[foreachiter1];`
which gives `undefined`
Seems like it was supposed to be
`foreachiter1_target.getProperty(foreachiter1);`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]