Browse Source

fix positions of identifiers in EFor (closes #5172) (closes #5173)

Simon Krajewski 9 years ago
parent
commit
64208e115d

+ 4 - 4
src/optimization/optimizer.ml

@@ -703,8 +703,8 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 		TField (e,try quick_field e.etype n with Not_found -> assert false)
 		TField (e,try quick_field e.etype n with Not_found -> assert false)
 	in
 	in
 	let gen_int_iter pt f_get f_length =
 	let gen_int_iter pt f_get f_length =
-		let i = add_local ctx i pt p in
-		let index = gen_local ctx t_int p in
+		let i = add_local ctx i pt pi in
+		let index = gen_local ctx t_int pi in
 		let arr, avars = (match e1.eexpr with
 		let arr, avars = (match e1.eexpr with
 			| TLocal _ -> e1, None
 			| TLocal _ -> e1, None
 			| _ ->
 			| _ ->
@@ -744,8 +744,8 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 			| _, TConst _ -> None
 			| _, TConst _ -> None
 			| _ -> Some (gen_local ctx t_int e1.epos)
 			| _ -> Some (gen_local ctx t_int e1.epos)
 		) in
 		) in
-		let tmp = gen_local ctx t_int e1.epos in
-		let i = add_local ctx i t_int e1.epos in
+		let tmp = gen_local ctx t_int pi in
+		let i = add_local ctx i t_int pi in
 		let rec check e =
 		let rec check e =
 			match e.eexpr with
 			match e.eexpr with
 			| TBinop (OpAssign,{ eexpr = TLocal l },_)
 			| TBinop (OpAssign,{ eexpr = TLocal l },_)

+ 3 - 1
src/typing/typer.ml

@@ -3549,7 +3549,9 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			(try Optimizer.optimize_for_loop_iterator ctx i e1 e2 p with Exit -> mk (TFor (i,e1,e2)) ctx.t.tvoid p)
 			(try Optimizer.optimize_for_loop_iterator ctx i e1 e2 p with Exit -> mk (TFor (i,e1,e2)) ctx.t.tvoid p)
 		in
 		in
 		let e = match Optimizer.optimize_for_loop ctx (i,pi) e1 e2 p with
 		let e = match Optimizer.optimize_for_loop ctx (i,pi) e1 e2 p with
-			| Some e -> e
+			| Some e ->
+				if display then ignore(handle_display ctx (EConst(Ident i),pi) false Value);
+				e
 			| None -> default()
 			| None -> default()
 		in
 		in
 		ctx.in_loop <- old_loop;
 		ctx.in_loop <- old_loop;

+ 1 - 1
tests/display/src/cases/Issue5166.hx

@@ -7,7 +7,7 @@ class Issue5166 extends DisplayTestCase {
 		}
 		}
 
 
 	**/
 	**/
-	function testHaxeUnitPort1() {
+	function test() {
 		eq("cases.E", type(pos(1)));
 		eq("cases.E", type(pos(1)));
 		eq(range(2, 3), position(pos(1)));
 		eq(range(2, 3), position(pos(1)));
 	}
 	}

+ 21 - 0
tests/display/src/cases/Issue5172.hx

@@ -0,0 +1,21 @@
+package cases;
+
+class Issue5172 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {
+			for ({-3-}i{-1-} in 0...10) {
+				{-4-}i{-2-};
+			}
+		}
+	}
+	**/
+	function test() {
+		eq("Int", type(pos(1)));
+		eq("Int", type(pos(2)));
+		eq(range(3, 1), position(pos(1)));
+		eq(range(3, 1), position(pos(2)));
+		arrayEq([range(4, 2)], usage(pos(1)));
+		arrayEq([range(4, 2)], usage(pos(2)));
+	}
+}

+ 22 - 0
tests/display/src/cases/Issue5173.hx

@@ -0,0 +1,22 @@
+package cases;
+
+class Issue5173 extends DisplayTestCase {
+	/**
+	class Main {
+		static function main() {
+			var map = new haxe.DynamicAccess();
+			for ({-3-}ke{-1-}y{-4-} in map.keys()) {
+				{-5-}ke{-2-}y{-6-};
+			}
+		}
+	}
+	**/
+	function test() {
+		eq("String", type(pos(1)));
+		eq("String", type(pos(2)));
+		eq(range(3, 4), position(pos(1)));
+		eq(range(3, 4), position(pos(2)));
+		arrayEq([range(5, 6)], usage(pos(1)));
+		arrayEq([range(5, 6)], usage(pos(2)));
+	}
+}