Browse Source

[python] fixed HaxeIterator.next when hasNext wasn't called before (closes #3191)

frabbit 11 years ago
parent
commit
dbda89b0c5
2 changed files with 16 additions and 0 deletions
  1. 1 0
      std/python/HaxeIterator.hx
  2. 15 0
      tests/unit/issues/Issue3191.hx

+ 1 - 0
std/python/HaxeIterator.hx

@@ -16,6 +16,7 @@ class HaxeIterator<T>
 	}
 
 	public inline function next ():T {
+		if (!checked) hasNext();
 		checked = false;
 		return x;
 	}

+ 15 - 0
tests/unit/issues/Issue3191.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+import unit.Test;
+
+class Issue3191 extends Test {
+
+	function test() {
+		var it = [1, 2, 3].iterator();
+        eq(1, it.next());
+        eq(true, it.hasNext());
+        eq(2, it.next());
+		eq(true, it.hasNext());
+		eq(3, it.next());
+		eq(false, it.hasNext());
+	}
+}