Browse Source

do not "optimize" for (i in e.iterator()) (fixed issue #1212)

Simon Krajewski 13 years ago
parent
commit
3df2043b18
2 changed files with 8 additions and 1 deletions
  1. 5 1
      optimizer.ml
  2. 3 0
      tests/unit/TestType.hx

+ 5 - 1
optimizer.ml

@@ -953,7 +953,11 @@ let optimize_completion_expr e =
 		| EFor ((EIn ((EConst (Ident n),_) as id,it),p),efor) ->
 			let it = loop it in
 			let old = save() in
-			decl n None (Some (ECall ((EField ((ECall ((EField (it,"iterator"),p),[]),p),"next"),p),[]),p));
+			let itfield = match fst it with
+				| ECall ((EField(_,"iterator"),_),[])-> it
+				| _ -> (ECall ((EField (it,"iterator"),p),[]),p)
+			in
+			decl n None (Some (ECall ((EField (itfield,"next"),p),[]),p));
 			let efor = loop efor in
 			old();
 			(EFor ((EIn (id,it),p),efor),p)

+ 3 - 0
tests/unit/TestType.hx

@@ -621,6 +621,9 @@ class TestType extends Test {
 		}'),"path(unknownVar)");
 		
 		
+		for (k in [s].iterator()) {
+			eq(complete("k.|"), "foo:Int");
+		}
 		#end
 	}