Prechádzať zdrojové kódy

add `v_pos`

It's gonna make sense, I swear!
Simon Krajewski 9 rokov pred
rodič
commit
d0197c2c5d

+ 6 - 6
src/generators/codegen.ml

@@ -577,9 +577,9 @@ type stack_context = {
 let stack_context_init com stack_var exc_var pos_var tmp_var use_add p =
 	let t = com.basic in
 	let st = t.tarray t.tstring in
-	let stack_var = alloc_var stack_var st in
-	let exc_var = alloc_var exc_var st in
-	let pos_var = alloc_var pos_var t.tint in
+	let stack_var = alloc_var stack_var st p in
+	let exc_var = alloc_var exc_var st p in
+	let pos_var = alloc_var pos_var t.tint p in
 	let stack_e = mk (TLocal stack_var) st p in
 	let exc_e = mk (TLocal exc_var) st p in
 	let stack_pop = fcall stack_e "pop" [] t.tstring p in
@@ -592,7 +592,7 @@ let stack_context_init com stack_var exc_var pos_var tmp_var use_add p =
 		] t.tvoid p
 	in
 	let stack_return e =
-		let tmp = alloc_var tmp_var e.etype in
+		let tmp = alloc_var tmp_var e.etype e.epos in
 		mk (TBlock [
 			mk (TVar (tmp, Some e)) t.tvoid e.epos;
 			stack_pop;
@@ -715,7 +715,7 @@ let fix_override com c f fd =
 					end;
 					cur
 				with Unify_error _ ->
-					let v2 = alloc_var (prefix ^ v.v_name) t2 in
+					let v2 = alloc_var (prefix ^ v.v_name) t2 v.v_pos in
 					changed_args := (v,v2) :: !changed_args;
 					v2,ct
 			) fd.tf_args targs in
@@ -972,7 +972,7 @@ let default_cast ?(vtmp="$t") com e texpr t p =
 		| TAbstractDecl a -> TAnon { a_fields = PMap.empty; a_status = ref (AbstractStatics a) }
 		| TTypeDecl _ -> assert false
 	in
-	let vtmp = alloc_var vtmp e.etype in
+	let vtmp = alloc_var vtmp e.etype e.epos in
 	let var = mk (TVar (vtmp,Some e)) api.tvoid p in
 	let vexpr = mk (TLocal vtmp) e.etype p in
 	let texpr = mk (TTypeExpr texpr) (mk_texpr texpr) p in

+ 1 - 1
src/generators/genas3.ml

@@ -840,7 +840,7 @@ and gen_value ctx e =
 	let value block =
 		let old = ctx.in_value in
 		let t = type_str ctx e.etype e.epos in
-		let r = alloc_var (gen_local ctx "$r") e.etype in
+		let r = alloc_var (gen_local ctx "$r") e.etype e.epos in
 		ctx.in_value <- Some r;
 		if ctx.in_static then
 			print ctx "function() : %s " t

+ 2 - 0
src/generators/gencommon.ml

@@ -48,6 +48,8 @@ open Option
 open Printf
 open ExtString
 
+let alloc_var n t = alloc_var n t null_pos
+
 let debug_type_ctor = function
 	| TMono _ -> "TMono"
 	| TEnum _ -> "TEnum"

+ 1 - 1
src/generators/genhl.ml

@@ -1932,7 +1932,7 @@ and eval_expr ctx e =
 				let eargs, et = (match follow ef.ef_type with TFun (args,ret) -> args, ret | _ -> assert false) in
 				let ct = ctx.com.basic in
 				let p = ef.ef_pos in
-				let eargs = List.map (fun (n,o,t) -> alloc_var n t, if o then Some TNull else None) eargs in
+				let eargs = List.map (fun (n,o,t) -> alloc_var n t en.e_pos, if o then Some TNull else None) eargs in
 				let ecall = mk (TCall (e,List.map (fun (v,_) -> mk (TLocal v) v.v_type p) eargs)) et p in
 				let f = {
 					tf_args = eargs;

+ 1 - 1
src/generators/genjs.ml

@@ -838,7 +838,7 @@ and gen_value ctx e =
 	in
 	let value() =
 		let old = ctx.in_value, ctx.in_loop in
-		let r = alloc_var "$r" t_dynamic in
+		let r = alloc_var "$r" t_dynamic e.epos in
 		ctx.in_value <- Some r;
 		ctx.in_loop <- false;
 		spr ctx "(function($this) ";

+ 4 - 4
src/generators/genlua.ml

@@ -941,7 +941,7 @@ and gen_value ctx e =
 	let value() =
 		let old = ctx.in_value, ctx.in_loop in
 		let r_id = temp ctx in
-		let r = alloc_var r_id t_dynamic in
+		let r = alloc_var r_id t_dynamic e.epos in
 		ctx.in_value <- Some r;
 		ctx.in_loop <- false;
 		spr ctx "(function() ";
@@ -1127,10 +1127,10 @@ and gen_tbinop ctx op e1 e2 =
     | Ast.OpAssignOp(op2), TArray(e3,e4), _ ->
 	    (* TODO: Figure out how to rewrite this expression more cleanly *)
 	    sprln ctx "(function() ";
-	    let idx = alloc_var "idx" e4.etype in
+	    let idx = alloc_var "idx" e4.etype e4.epos in
 	    let idx_var =  mk (TVar( idx , Some(e4))) e4.etype e4.epos in
 	    gen_expr ctx idx_var;
-	    let arr = alloc_var "arr" e3.etype in
+	    let arr = alloc_var "arr" e3.etype e3.epos in
 	    let arr_var = mk (TVar(arr, Some(e3))) e3.etype e3.epos in
 	    gen_expr ctx arr_var;
 	    newline ctx;
@@ -1145,7 +1145,7 @@ and gen_tbinop ctx op e1 e2 =
     | Ast.OpAssignOp(op2), TField(e3,e4), _ ->
 	    (* TODO: Figure out how to rewrite this expression more cleanly *)
 	    sprln ctx "(function() ";
-	    let obj = alloc_var "obj" e3.etype in
+	    let obj = alloc_var "obj" e3.etype e3.epos in
 	    spr ctx "local fld = ";
 	    (match e4 with
 	    | FInstance(_,_,fld)

+ 2 - 2
src/generators/genphp.ml

@@ -209,7 +209,7 @@ let rec is_string_type t =
 let is_string_expr e = is_string_type e.etype
 
 let to_string ctx e =
-	let v = alloc_var "__call__" t_dynamic in
+	let v = alloc_var "__call__" t_dynamic e.epos in
 	let f = mk (TLocal v) t_dynamic e.epos in
 	mk (TCall (f, [ Codegen.string ctx.com "_hx_string_rec" e.epos; e; Codegen.string ctx.com "" e.epos])) ctx.com.basic.tstring e.epos
 
@@ -222,7 +222,7 @@ let as_string_expr ctx e =
 	| _ -> e
 (* for known String type that could have null value *)
 let to_string_null ctx e =
-	let v = alloc_var "__call__" t_dynamic in
+	let v = alloc_var "__call__" t_dynamic e.epos in
 	let f = mk (TLocal v) t_dynamic e.epos in
 	mk (TCall (f, [ Codegen.string ctx.com "_hx_string_or_null" e.epos; e])) ctx.com.basic.tstring e.epos
 

+ 22 - 22
src/generators/genpy.ml

@@ -172,19 +172,19 @@ module Transformer = struct
 	let lift_expr1 is_value next_id blocks e =
 		lift_expr ~is_value:is_value ~next_id:(Some next_id) ~blocks:blocks e
 
-	let to_tvar ?(capture = false) n t =
-		alloc_var n t
+	let to_tvar ?(capture = false) n t p =
+		alloc_var n t p
 		(* { v_name = n; v_type = t; v_id = 0; v_capture = capture; v_extra = None; v_meta = [] } *)
 
 	let create_non_local n pos =
 		let s = "nonlocal " ^ (KeywordHandler.handle_keywords n) in
 		(* TODO: this is a hack... *)
-		let id = mk (TLocal (to_tvar "python_Syntax._pythonCode" t_dynamic ) ) !t_void pos in
-		let id2 = mk (TLocal( to_tvar s t_dynamic )) !t_void pos in
+		let id = mk (TLocal (to_tvar "python_Syntax._pythonCode" t_dynamic pos) ) !t_void pos in
+		let id2 = mk (TLocal( to_tvar s t_dynamic pos)) !t_void pos in
 		mk (TCall(id, [id2])) t_dynamic pos
 
 	let to_tlocal_expr ?(capture = false) n t p =
-		mk (TLocal (to_tvar ~capture:capture n t)) t p
+		mk (TLocal (to_tvar ~capture:capture n t p)) t p
 
 	let check_unification e t = match follow e.etype,follow t with
 		| TAnon an1, TAnon an2 ->
@@ -204,7 +204,7 @@ module Transformer = struct
 
 	let dynamic_field_read_write next_id e1 s op e2 t =
 		let id = next_id() in
-		let temp_var = to_tvar id e1.etype in
+		let temp_var = to_tvar id e1.etype e1.epos in
 		let temp_var_def = mk (TVar(temp_var,Some e1)) e1.etype e1.epos in
 		let temp_local = mk (TLocal temp_var) e1.etype e1.epos in
 		let e_field = dynamic_field_read temp_local s t in
@@ -300,7 +300,7 @@ module Transformer = struct
 		let fn = add_non_locals_to_func fn in
 		if is_value then begin
 			let new_name = ae.a_next_id() in
-			let new_var = alloc_var new_name tf.tf_type in
+			let new_var = alloc_var new_name tf.tf_type p in
 			let new_local = mk (TLocal new_var) fn.etype p in
 			let def = mk (TVar(new_var,Some fn)) fn.etype p in
 			lift_expr1 false ae.a_next_id [def] new_local
@@ -434,7 +434,7 @@ module Transformer = struct
 			let c_string = match !t_string with TInst(c,_) -> c | _ -> assert false in
 			let cf_length = PMap.find "length" c_string.cl_fields in
 			let ef = mk (TField(e1,FInstance(c_string,[],cf_length))) !t_int e1.epos in
-			let res_var = alloc_var (ae.a_next_id()) ef.etype in
+			let res_var = alloc_var (ae.a_next_id()) ef.etype ef.epos in
 			let res_local = {ef with eexpr = TLocal res_var} in
 			let var_expr = {ef with eexpr = TVar(res_var,Some ef)} in
 			let e = mk (TBlock [
@@ -447,7 +447,7 @@ module Transformer = struct
 		let e1_ = transform_expr e1 ~is_value:true ~next_id:(Some ae.a_next_id) in
 		let handle_as_local temp_local =
 			let ex = ae.a_expr in
-			let res_var = alloc_var (ae.a_next_id()) ex.etype in
+			let res_var = alloc_var (ae.a_next_id()) ex.etype ex.epos in
 			let res_local = {ex with eexpr = TLocal res_var} in
 			let plus = {ex with eexpr = TBinop(op,temp_local,one)} in
 			let var_expr = {ex with eexpr = TVar(res_var,Some temp_local)} in
@@ -474,17 +474,17 @@ module Transformer = struct
 				handle_as_local e1_.a_expr
 			| TArray(e1,e2) ->
 				let id = ae.a_next_id() in
-				let temp_var_l = alloc_var id e1.etype in
+				let temp_var_l = alloc_var id e1.etype e1.epos in
 				let temp_local_l = {e1 with eexpr = TLocal temp_var_l} in
 				let temp_var_l = {e1 with eexpr = TVar(temp_var_l,Some e1)} in
 
 				let id = ae.a_next_id() in
-				let temp_var_r = alloc_var id e2.etype in
+				let temp_var_r = alloc_var id e2.etype e2.epos in
 				let temp_local_r = {e2 with eexpr = TLocal temp_var_r} in
 				let temp_var_r = {e2 with eexpr = TVar(temp_var_r,Some e2)} in
 
 				let id = ae.a_next_id() in
-				let temp_var = alloc_var id e1_.a_expr.etype in
+				let temp_var = alloc_var id e1_.a_expr.etype e1_.a_expr.epos in
 				let temp_local = {e1_.a_expr with eexpr = TLocal temp_var} in
 				let temp_var_expr = {e1_.a_expr with eexpr = TArray(temp_local_l,temp_local_r)} in
 				let temp_var = {e1_.a_expr with eexpr = TVar(temp_var,Some temp_var_expr)} in
@@ -498,11 +498,11 @@ module Transformer = struct
 				end else
 					transform_exprs_to_block block ae.a_expr.etype false ae.a_expr.epos ae.a_next_id
 			| TField(e1,fa) ->
-				let temp_var_l = alloc_var (ae.a_next_id()) e1.etype in
+				let temp_var_l = alloc_var (ae.a_next_id()) e1.etype e1.epos in
 				let temp_local_l = {e1 with eexpr = TLocal temp_var_l} in
 				let temp_var_l = {e1 with eexpr = TVar(temp_var_l,Some e1)} in
 
-				let temp_var = alloc_var (ae.a_next_id()) e1_.a_expr.etype in
+				let temp_var = alloc_var (ae.a_next_id()) e1_.a_expr.etype e1_.a_expr.epos in
 				let temp_local = {e1_.a_expr with eexpr = TLocal temp_var} in
 				let temp_var_expr = {e1_.a_expr with eexpr = TField(temp_local_l,fa)} in
 				let temp_var = {e1_.a_expr with eexpr = TVar(temp_var,Some temp_var_expr)} in
@@ -520,7 +520,7 @@ module Transformer = struct
 				assert false
 
 	and var_to_treturn_expr ?(capture = false) n t p =
-		let x = mk (TLocal (to_tvar ~capture:capture n t)) t p in
+		let x = mk (TLocal (to_tvar ~capture:capture n t p)) t p in
 		mk (TReturn (Some x)) t p
 
 	and exprs_to_func exprs name base =
@@ -567,7 +567,7 @@ module Transformer = struct
 			in
 			let f1 = { tf_args = []; tf_type = TFun([],ex.etype); tf_expr = ex} in
 			let fexpr = mk (TFunction f1) ex.etype ex.epos in
-			let fvar = to_tvar name fexpr.etype in
+			let fvar = to_tvar name fexpr.etype fexpr.epos in
 			let f = add_non_locals_to_func fexpr in
 			let assign = { ex with eexpr = TVar(fvar, Some(f))} in
 			let call_expr = (mk (TLocal fvar) fexpr.etype ex.epos ) in
@@ -626,7 +626,7 @@ module Transformer = struct
 				tf_type = tr;
 				tf_expr = my_block.a_expr;
 			}) ae.a_expr.etype ae.a_expr.epos in
-			let t_var = alloc_var name ae.a_expr.etype in
+			let t_var = alloc_var name ae.a_expr.etype ae.a_expr.epos in
 			let f = add_non_locals_to_func fn in
 			let fn_assign = mk (TVar (t_var,Some f)) ae.a_expr.etype ae.a_expr.epos in
 			let ev = mk (TLocal t_var) ae.a_expr.etype ae.a_expr.epos in
@@ -655,7 +655,7 @@ module Transformer = struct
 			let a2 = to_expr (trans false [] e2) in
 
 			let name = (ae.a_next_id ()) in
-			let t_var = alloc_var name e1.etype in
+			let t_var = alloc_var name e1.etype e1.epos in
 
 			let ev = make_local t_var e1.epos in
 			let ehasnext = mk (TField(ev,quick_field e1.etype "hasNext")) (tfun [] (!t_bool) ) e1.epos in
@@ -685,7 +685,7 @@ module Transformer = struct
 				tf_expr = e1;
 			}) ef.etype ef.epos in
 			let f1 = add_non_locals_to_func f in
-			let var_n = alloc_var n ef.etype in
+			let var_n = alloc_var n ef.etype ef.epos in
 			let f1_assign = mk (TVar(var_n,Some f1)) !t_void f1.epos in
 			let var_local = mk (TLocal var_n) ef.etype f1.epos in
 			let er = mk (TReturn (Some var_local)) t_dynamic  ae.a_expr.epos in
@@ -897,7 +897,7 @@ module Transformer = struct
 		| (true, TTry(etry, catches)) ->
 
 			let id = ae.a_next_id () in
-			let temp_var = to_tvar id a_expr.etype in
+			let temp_var = to_tvar id a_expr.etype a_expr.epos in
 			let temp_var_def = { a_expr with eexpr = TVar(temp_var, None) } in
 			let temp_local = { a_expr with eexpr = TLocal(temp_var)} in
 			let mk_temp_assign right = { a_expr with eexpr = TBinop(OpAssign, temp_local, right)} in
@@ -1850,7 +1850,7 @@ module Generator = struct
 					| e_last :: el ->
 						let new_last = {e_last with eexpr = TReturn (Some e_last)} in
 						let new_block = {expr2 with eexpr = TBlock (List.rev (new_last :: el))} in
-						let v_name = alloc_var name (tfun [] e_last.etype) in
+						let v_name = alloc_var name (tfun [] e_last.etype) e_last.epos in
 						let f_name = mk (TLocal v_name) v_name.v_type e_last.epos in
 						let call_f = mk (TCall(f_name,[])) e_last.etype e_last.epos in
 						Some new_block,call_f
@@ -1880,7 +1880,7 @@ module Generator = struct
 		let e = match e.eexpr with
 			| TFunction(f) ->
 				let args = List.map (fun s ->
-					alloc_var s t_dynamic,None
+					alloc_var s t_dynamic p,None
 				) extra_args in
 				{e with eexpr = TFunction {f with tf_args = args @ f.tf_args}}
 			| _ ->

+ 3 - 3
src/generators/genswf9.ml

@@ -1994,7 +1994,7 @@ let generate_field_kind ctx f c stat =
 			) args;
 			let dparams = (match !dparams with None -> None | Some l -> Some (List.rev l)) in
 			Some (HFMethod {
-				hlm_type = end_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t, (if opt then Some TNull else None)) args) dparams tret;
+				hlm_type = end_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t f.cf_pos, (if opt then Some TNull else None)) args) dparams tret;
 				hlm_final = false;
 				hlm_override = false;
 				hlm_kind = snd (method_kind());
@@ -2193,7 +2193,7 @@ let generate_class ctx c =
 let generate_enum ctx e meta =
 	let name_id = type_path ctx e.e_path in
 	let api = ctx.com.basic in
-	let f = begin_fun ctx [alloc_var "tag" api.tstring, None;alloc_var "index" api.tint, None;alloc_var "params" (api.tarray (mk_mono())), None] api.tvoid [ethis] false e.e_pos in
+	let f = begin_fun ctx [alloc_var "tag" api.tstring e.e_pos, None;alloc_var "index" api.tint e.e_pos, None;alloc_var "params" (api.tarray (mk_mono())) e.e_pos, None] api.tvoid [ethis] false e.e_pos in
 	let tag_id = ident "tag" in
 	let index_id = ident "index" in
 	let params_id = ident "params" in
@@ -2224,7 +2224,7 @@ let generate_enum ctx e meta =
 			hlf_slot = !st_count;
 			hlf_kind = (match f.ef_type with
 				| TFun (args,_) ->
-					let fdata = begin_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t, (if opt then Some TNull else None)) args) (TEnum (e,[])) [] true f.ef_pos in
+					let fdata = begin_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t e.e_pos, (if opt then Some TNull else None)) args) (TEnum (e,[])) [] true f.ef_pos in
 					write ctx (HFindPropStrict name_id);
 					write ctx (HString f.ef_name);
 					write ctx (HInt f.ef_index);

+ 2 - 2
src/optimization/analyzer.ml

@@ -139,7 +139,7 @@ module Ssa = struct
 	let rec rename_in_block ctx bb =
 		let write_var v is_phi i =
 			update_reaching_def ctx v bb;
-			let v' = alloc_var (v.v_name) v.v_type in
+			let v' = alloc_var (v.v_name) v.v_type v.v_pos in
 			declare_var ctx.graph v' bb;
 			v'.v_meta <- v.v_meta;
 			v'.v_capture <- v.v_capture;
@@ -665,7 +665,7 @@ module CodeMotion = DataFlow(struct
 					let v' = if decl then begin
 						v
 					end else begin
-						let v' = alloc_var ctx.temp_var_name v.v_type in
+						let v' = alloc_var ctx.temp_var_name v.v_type v.v_pos in
 						declare_var ctx.graph v' bb_loop_pre;
 						v'.v_meta <- [Meta.CompilerGenerated,[],p];
 						v'

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -248,7 +248,7 @@ module TexprFilter = struct
 			let e = mk (TWhile(Codegen.mk_parent e_true,e_block,NormalWhile)) e.etype p in
 			loop e
 		| TFor(v,e1,e2) ->
-			let v' = alloc_var "tmp" e1.etype in
+			let v' = alloc_var "tmp" e1.etype e1.epos in
 			let ev' = mk (TLocal v') e1.etype e1.epos in
 			let t1 = (Abstract.follow_with_abstracts e1.etype) in
 			let ehasnext = mk (TField(ev',quick_field t1 "hasNext")) (tfun [] com.basic.tbool) e1.epos in

+ 1 - 1
src/optimization/analyzerTexprTransformer.ml

@@ -202,7 +202,7 @@ let rec func ctx bb tf t p =
 				fl,e
 		in
 		let fl,e = loop [] e in
-		let v = alloc_var ctx.temp_var_name e.etype in
+		let v = alloc_var ctx.temp_var_name e.etype e.epos in
 		begin match ctx.com.platform with
 			| Cpp when sequential && not (Common.defined ctx.com Define.Cppia) -> ()
 			| _ -> v.v_meta <- [Meta.CompilerGenerated,[],e.epos];

+ 3 - 3
src/optimization/filters.ml

@@ -327,7 +327,7 @@ let captured_vars com e =
 	in
 
 	let mk_var v used =
-		let v2 = alloc_var v.v_name (PMap.find v.v_id used) in
+		let v2 = alloc_var v.v_name (PMap.find v.v_id used) v.v_pos in
 		v2.v_meta <- v.v_meta;
 		v2
 	in
@@ -393,7 +393,7 @@ let captured_vars com e =
 			*)
 			if com.config.pf_capture_policy = CPLoopVars then
 				(* We don't want to duplicate any variable declarations, so let's make copies (issue #3902). *)
-				let new_vars = List.map (fun v -> v.v_id,alloc_var v.v_name v.v_type) vars in
+				let new_vars = List.map (fun v -> v.v_id,alloc_var v.v_name v.v_type v.v_pos) vars in
 				let rec loop e = match e.eexpr with
 					| TLocal v ->
 						begin try
@@ -802,7 +802,7 @@ let add_field_inits ctx t =
 	let apply c =
 		let ethis = mk (TConst TThis) (TInst (c,List.map snd c.cl_params)) c.cl_pos in
 		(* TODO: we have to find a variable name which is not used in any of the functions *)
-		let v = alloc_var "_g" ethis.etype in
+		let v = alloc_var "_g" ethis.etype ethis.epos in
 		let need_this = ref false in
 		let inits,fields = List.fold_left (fun (inits,fields) cf ->
 			match cf.cf_kind,cf.cf_expr with

+ 15 - 15
src/optimization/optimizer.ml

@@ -57,7 +57,7 @@ let rec is_exhaustive e1 = match e1.eexpr with
 
 let mk_untyped_call name p params =
 	{
-		eexpr = TCall({ eexpr = TLocal(alloc_unbound_var name t_dynamic); etype = t_dynamic; epos = p }, params);
+		eexpr = TCall({ eexpr = TLocal(alloc_unbound_var name t_dynamic p); etype = t_dynamic; epos = p }, params);
 		etype = t_dynamic;
 		epos = p;
 	}
@@ -161,7 +161,7 @@ let api_inline ctx c field params p = match c.cl_path, field, params with
 			mk (TLocal (try
 				PMap.find n ctx.locals
 			with _ ->
-				let v = add_local ctx n t in
+				let v = add_local ctx n t p in
 				v.v_meta <- [Meta.Unbound,[],p];
 				v
 			)) t pos in
@@ -319,7 +319,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 		try
 			Hashtbl.find locals v.v_id
 		with Not_found ->
-			let v' = alloc_var v.v_name v.v_type in
+			let v' = alloc_var v.v_name v.v_type v.v_pos in
 			if Meta.has Meta.Unbound v.v_meta then v'.v_meta <- [Meta.Unbound,[],p];
 			let i = {
 				i_var = v;
@@ -390,7 +390,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 		Build the expr/var subst list
 	*)
 	let ethis = (match ethis.eexpr with TConst TSuper -> { ethis with eexpr = TConst TThis } | _ -> ethis) in
-	let vthis = alloc_var "_this" ethis.etype in
+	let vthis = alloc_var "_this" ethis.etype ethis.epos in
 	let might_be_affected,collect_modified_locals = create_affection_checker() in
 	let had_side_effect = ref false in
 	let inlined_vars = List.map2 (fun e (v,_) ->
@@ -703,12 +703,12 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 		TField (e,try quick_field e.etype n with Not_found -> assert false)
 	in
 	let gen_int_iter pt f_get f_length =
-		let i = add_local ctx i pt in
-		let index = gen_local ctx t_int in
+		let i = add_local ctx i pt p in
+		let index = gen_local ctx t_int p in
 		let arr, avars = (match e1.eexpr with
 			| TLocal _ -> e1, None
 			| _ ->
-				let atmp = gen_local ctx e1.etype in
+				let atmp = gen_local ctx e1.etype e1.epos in
 				mk (TLocal atmp) e1.etype e1.epos, (Some (atmp,Some e1))
 		) in
 		let iexpr = mk (TLocal index) t_int p in
@@ -742,10 +742,10 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 		let max = (match i1.eexpr , i2.eexpr with
 			| TConst (TInt a), TConst (TInt b) when Int32.compare b a < 0 -> error "Range operator can't iterate backwards" p
 			| _, TConst _ -> None
-			| _ -> Some (gen_local ctx t_int)
+			| _ -> Some (gen_local ctx t_int e1.epos)
 		) in
-		let tmp = gen_local ctx t_int in
-		let i = add_local ctx i t_int in
+		let tmp = gen_local ctx t_int e1.epos in
+		let i = add_local ctx i t_int e1.epos in
 		let rec check e =
 			match e.eexpr with
 			| TBinop (OpAssign,{ eexpr = TLocal l },_)
@@ -803,7 +803,7 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 					Ast.map_expr loop e
 			in
 			ignore(loop e2);
-			let v = add_local ctx i pt in
+			let v = add_local ctx i pt p in
 			let e2 = type_expr ctx e2 NoValue in
 			let cost = (List.length el) * !num_expr in
 			let max_cost = try
@@ -863,8 +863,8 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 		end
 	| _ , TInst ({ cl_kind = KGenericInstance ({ cl_path = ["haxe";"ds"],"GenericStack" },[t]) } as c,[]) ->
 		let tcell = (try (PMap.find "head" c.cl_fields).cf_type with Not_found -> assert false) in
-		let i = add_local ctx i t in
-		let cell = gen_local ctx tcell in
+		let i = add_local ctx i t p in
+		let cell = gen_local ctx tcell p in
 		let cexpr = mk (TLocal cell) tcell p in
 		let e2 = type_expr ctx e2 NoValue in
 		let evar = mk (TVar (i,Some (mk (mk_field cexpr "elt") t p))) t_void pi in
@@ -888,7 +888,7 @@ let optimize_for_loop_iterator ctx v e1 e2 p =
 	let c,tl = (match follow e1.etype with TInst (c,pl) -> c,pl | _ -> raise Exit) in
 	let _, _, fhasnext = (try raw_class_field (fun cf -> apply_params c.cl_params tl cf.cf_type) c tl "hasNext" with Not_found -> raise Exit) in
 	if fhasnext.cf_kind <> Method MethInline then raise Exit;
-	let tmp = gen_local ctx e1.etype in
+	let tmp = gen_local ctx e1.etype e1.epos in
 	let eit = mk (TLocal tmp) e1.etype p in
 	let ehasnext = make_call ctx (mk (TField (eit,FInstance (c, tl, fhasnext))) (TFun([],ctx.t.tbool)) p) [] ctx.t.tbool p in
 	let enext = mk (TVar (v,Some (make_call ctx (mk (TField (eit,quick_field_dynamic eit.etype "next")) (TFun ([],v.v_type)) p) [] v.v_type p))) ctx.t.tvoid p in
@@ -1428,7 +1428,7 @@ let inline_constructors ctx e =
 	in
 	let add_field_var v s t =
 		let ii = IntMap.find v.v_id !vars in
-		let v' = alloc_var (Printf.sprintf "%s_%s" v.v_name s) t in
+		let v' = alloc_var (Printf.sprintf "%s_%s" v.v_name s) t v.v_pos in
 		ii.ii_fields <- PMap.add s v' ii.ii_fields;
 		v'
 	in

+ 3 - 3
src/typing/matcher.ml

@@ -176,7 +176,7 @@ module Pattern = struct
 				pctx.current_locals <- PMap.add name (v,p) pctx.current_locals;
 				v
 			| _ ->
-				let v = alloc_var name t in
+				let v = alloc_var name t (pos e) in
 				pctx.current_locals <- PMap.add name (v,(pos e)) pctx.current_locals;
 				ctx.locals <- PMap.add name v ctx.locals;
 				v
@@ -1028,7 +1028,7 @@ module Compile = struct
 					let v,_,_ = List.find (fun (_,_,e2) -> Texpr.equal e1 e2) ex_bindings in
 					v,ex_bindings
 				with Not_found ->
-					let v = alloc_var "_hx_tmp" e1.etype in
+					let v = alloc_var "_hx_tmp" e1.etype e1.epos in
 					v,(v,e1.epos,e1) :: ex_bindings
 				in
 				let ev = mk (TLocal v) v.v_type e1.epos in
@@ -1054,7 +1054,7 @@ module Compile = struct
 			| TConst _ | TLocal _ ->
 				(e :: subjects,vars)
 			| _ ->
-				let v = gen_local ctx e.etype in
+				let v = gen_local ctx e.etype e.epos in
 				let ev = mk (TLocal v) e.etype e.epos in
 				(ev :: subjects,(v,e.epos,e) :: vars)
 		) ([],[]) subjects in

+ 5 - 4
src/typing/type.ml

@@ -78,6 +78,7 @@ and tvar = {
 	mutable v_capture : bool;
 	mutable v_extra : tvar_extra;
 	mutable v_meta : metadata;
+	v_pos : pos;
 }
 
 and tfunc = {
@@ -309,10 +310,10 @@ and build_state =
 
 let alloc_var =
 	let uid = ref 0 in
-	(fun n t -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None; v_meta = [] })
+	(fun n t p -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None; v_meta = []; v_pos = p })
 
-let alloc_unbound_var n t =
-	let v = alloc_var n t in
+let alloc_unbound_var n t p =
+	let v = alloc_var n t p in
 	v.v_meta <- [Meta.Unbound,[],null_pos];
 	v
 
@@ -2529,7 +2530,7 @@ module Texpr = struct
 	let duplicate_tvars e =
 		let vars = Hashtbl.create 0 in
 		let copy_var v =
-			let v2 = alloc_var v.v_name v.v_type in
+			let v2 = alloc_var v.v_name v.v_type v.v_pos in
 			v2.v_meta <- v.v_meta;
 			Hashtbl.add vars v.v_id v2;
 			v2;

+ 4 - 4
src/typing/typecore.ml

@@ -289,14 +289,14 @@ let save_locals ctx =
 	let locals = ctx.locals in
 	(fun() -> ctx.locals <- locals)
 
-let add_local ctx n t =
-	let v = alloc_var n t in
+let add_local ctx n t p =
+	let v = alloc_var n t p in
 	ctx.locals <- PMap.add n v ctx.locals;
 	v
 
 let gen_local_prefix = "`"
 
-let gen_local ctx t =
+let gen_local ctx t p =
 	(* ensure that our generated local does not mask an existing one *)
 	let rec loop n =
 		let nv = (if n = 0 then gen_local_prefix else gen_local_prefix ^ string_of_int n) in
@@ -305,7 +305,7 @@ let gen_local ctx t =
 		else
 			nv
 	in
-	add_local ctx (loop 0) t
+	add_local ctx (loop 0) t p
 
 let is_gen_local v =
 	String.unsafe_get v.v_name 0 = String.unsafe_get gen_local_prefix 0

+ 5 - 5
src/typing/typeload.ml

@@ -1243,12 +1243,12 @@ let add_constructor ctx c force_constructor p =
 					| TFun (args,_) ->
 						List.map (fun (n,o,t) ->
 							let def = try type_function_arg_value ctx t (Some (PMap.find n values)) with Not_found -> if o then Some TNull else None in
-							map_arg (alloc_var n (if o then ctx.t.tnull t else t),def)
+							map_arg (alloc_var n (if o then ctx.t.tnull t else t) p,def) (* TODO: var pos *)
 						) args
 					| _ -> assert false
 			) in
 			let p = c.cl_pos in
-			let vars = List.map (fun (v,def) -> alloc_var v.v_name (apply_params csup.cl_params cparams v.v_type), def) args in
+			let vars = List.map (fun (v,def) -> alloc_var v.v_name (apply_params csup.cl_params cparams v.v_type) v.v_pos, def) args in
 			let super_call = mk (TCall (mk (TConst TSuper) (TInst (csup,cparams)) p,List.map (fun (v,_) -> mk (TLocal v) v.v_type p) vars)) ctx.t.tvoid p in
 			let constr = mk (TFunction {
 				tf_args = vars;
@@ -1289,7 +1289,7 @@ let check_struct_init_constructor ctx c p = match c.cl_constructor with
 			| Var _ ->
 				let opt = Meta.has Meta.Optional cf.cf_meta in
 				let t = if opt then ctx.t.tnull cf.cf_type else cf.cf_type in
-				let v = alloc_var cf.cf_name t in
+				let v = alloc_var cf.cf_name t p in
 				let ef = mk (TField(ethis,FInstance(c,params,cf))) t p in
 				let ev = mk (TLocal v) v.v_type p in
 				let e = mk (TBinop(OpAssign,ef,ev)) ev.etype p in
@@ -1595,7 +1595,7 @@ let type_function ctx args ret fmode f do_display p =
 	let fargs = List.map (fun (n,c,t) ->
 		if n.[0] = '$' then error "Function argument names starting with a dollar are not allowed" p;
 		let c = type_function_arg_value ctx t c in
-		let v,c = add_local ctx n t, c in
+		let v,c = add_local ctx n t p, c in (* TODO: var pos *)
 		if n = "this" then v.v_meta <- (Meta.This,[],p) :: v.v_meta;
 		v,c
 	) args in
@@ -3691,7 +3691,7 @@ let generic_substitute_expr gctx e =
 		try
 			Hashtbl.find vars v.v_id
 		with Not_found ->
-			let v2 = alloc_var v.v_name (generic_substitute_type gctx v.v_type) in
+			let v2 = alloc_var v.v_name (generic_substitute_type gctx v.v_type) v.v_pos in
 			v2.v_meta <- v.v_meta;
 			Hashtbl.add vars v.v_id v2;
 			v2

+ 32 - 32
src/typing/typer.ml

@@ -1016,9 +1016,9 @@ let rec acc_get ctx g p =
 			(* arguments might not have names in case of variable fields of function types, so we generate one (issue #2495) *)
 			let args = List.map (fun (n,o,t) ->
 				let t = if o then ctx.t.tnull t else t in
-				o,if n = "" then gen_local ctx t else alloc_var n t
+				o,if n = "" then gen_local ctx t e.epos else alloc_var n t e.epos (* TODO: var pos *)
 			) args in
-			let ve = alloc_var "_e" e.etype in
+			let ve = alloc_var "_e" e.etype e.epos in
 			let ecall = make_call ctx et (List.map (fun v -> mk (TLocal v) v.v_type p) (ve :: List.map snd args)) ret p in
 			let ecallb = mk (TFunction {
 				tf_args = List.map (fun (o,v) -> v,if o then Some TNull else None) args;
@@ -1119,7 +1119,7 @@ let get_this ctx p =
 				let v = if ctx.curfun = FunMemberAbstractLocal then
 					PMap.find "this" ctx.locals
 				else
-					add_local ctx "`this" ctx.tthis
+					add_local ctx "`this" ctx.tthis p
 				in
 				ctx.vthis <- Some v;
 				v
@@ -1718,12 +1718,12 @@ let type_bind ctx (e : texpr) params p =
 			error "Usage of _ is not supported for optional non-nullable arguments" p
 		| (n,o,t) :: args , ([] as params)
 		| (n,o,t) :: args , (EConst(Ident "_"),_) :: params ->
-			let v = alloc_var (alloc_name n) (if o then ctx.t.tnull t else t) in
+			let v = alloc_var (alloc_name n) (if o then ctx.t.tnull t else t) p in
 			loop args params given_args (missing_args @ [v,o]) (ordered_args @ [vexpr v])
 		| (n,o,t) :: args , param :: params ->
 			let e = type_expr ctx param (WithType t) in
 			unify ctx e.etype t p;
-			let v = alloc_var (alloc_name n) t in
+			let v = alloc_var (alloc_name n) t (pos param) in
 			loop args params (given_args @ [v,o,Some e]) missing_args (ordered_args @ [vexpr v])
 	in
 	let given_args,missing_args,ordered_args = loop args params [] [] [] in
@@ -1731,7 +1731,7 @@ let type_bind ctx (e : texpr) params p =
 		let name = if n = 0 then "f" else "f" ^ (string_of_int n) in
 		if List.exists (fun (n,_,_) -> name = n) args then gen_loc_name (n + 1) else name
 	in
-	let loc = alloc_var (gen_loc_name 0) e.etype in
+	let loc = alloc_var (gen_loc_name 0) e.etype e.epos in
 	let given_args = (loc,false,Some e) :: given_args in
 	let inner_fun_args l = List.map (fun (v,o) -> v.v_name, o, v.v_type) l in
 	let t_inner = TFun(inner_fun_args missing_args, ret) in
@@ -1966,7 +1966,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 		| AKNo s -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
 		| AKExpr e ->
 			let save = save_locals ctx in
-			let v = gen_local ctx e.etype in
+			let v = gen_local ctx e.etype e.epos in
 			let has_side_effect = Optimizer.has_side_effect e in
 			let e1 = if has_side_effect then (EConst(Ident v.v_name),e.epos) else e1 in
 			let eop = type_binop ctx op e1 e2 true with_type p in
@@ -1981,9 +1981,9 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 				check_assign ctx e;
 				begin match e.eexpr with
 					| TArray(ea1,ea2) when has_side_effect ->
-						let v1 = gen_local ctx ea1.etype in
+						let v1 = gen_local ctx ea1.etype ea1.epos in
 						let ev1 = mk (TLocal v1) v1.v_type p in
-						let v2 = gen_local ctx ea2.etype in
+						let v2 = gen_local ctx ea2.etype ea2.epos in
 						let ev2 = mk (TLocal v2) v2.v_type p in
 						let e = {e with eexpr = TArray(ev1,ev2)} in
 						mk (TBlock [
@@ -1993,7 +1993,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 							mk (TBinop (OpAssign,e,e2)) e.etype p;
 						]) e.etype p
 					| TField(ea1,fa) when has_side_effect ->
-						let v1 = gen_local ctx ea1.etype in
+						let v1 = gen_local ctx ea1.etype ea1.epos in
 						let ev1 = mk (TLocal v1) v1.v_type p in
 						let e = {e with eexpr = TField(ev1,fa)} in
 						mk (TBlock [
@@ -2010,7 +2010,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 				eop)
 		| AKSet (e,t,cf) ->
 			let l = save_locals ctx in
-			let v = gen_local ctx e.etype in
+			let v = gen_local ctx e.etype e.epos in
 			let ev = mk (TLocal v) e.etype p in
 			let get = type_binop ctx op (EField ((EConst (Ident v.v_name),p),cf.cf_name),p) e2 true with_type p in
 			let e' = match get.eexpr with
@@ -2036,7 +2036,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			let l = save_locals ctx in
 			let v,is_temp = match et.eexpr with
 				| TLocal v when not (v.v_name = "this") -> v,false
-				| _ -> gen_local ctx ta,true
+				| _ -> gen_local ctx ta ef.epos,true
 			in
 			let ev = mk (TLocal v) ta p in
 			(* this relies on the fact that cf_name is set_name *)
@@ -2059,7 +2059,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 				| Some e -> e, fun () -> None
 				| None ->
 					let save = save_locals ctx in
-					let v = gen_local ctx ekey.etype in
+					let v = gen_local ctx ekey.etype p in
 					let e = mk (TLocal v) ekey.etype p in
 					e, fun () -> (save(); Some (mk (TVar (v,Some ekey)) ctx.t.tvoid p))
 			in
@@ -2381,7 +2381,7 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 							else if not (Optimizer.has_side_effect e1) && not (Optimizer.has_side_effect e2) then
 								make e1 e2
 							else
-								let v1,v2 = gen_local ctx t1, gen_local ctx t2 in
+								let v1,v2 = gen_local ctx t1 e1.epos, gen_local ctx t2 e2.epos in
 								let ev1,ev2 = mk (TVar(v1,Some e1)) ctx.t.tvoid p,mk (TVar(v2,Some e2)) ctx.t.tvoid p in
 								let eloc1,eloc2 = mk (TLocal v1) v1.v_type p,mk (TLocal v2) v2.v_type p in
 								let e = make eloc1 eloc2 in
@@ -2488,12 +2488,12 @@ and type_unop ctx op flag e p =
 		| AKAccess(a,tl,c,ebase,ekey) ->
 			begin try
 				(match op with Increment | Decrement -> () | _ -> raise Not_found);
-				let v_key = alloc_var "tmp" ekey.etype in
+				let v_key = alloc_var "tmp" ekey.etype ekey.epos in
 				let evar_key = mk (TVar(v_key,Some ekey)) ctx.com.basic.tvoid ekey.epos in
 				let ekey = mk (TLocal v_key) ekey.etype ekey.epos in
 				(* get *)
 				let e_get = mk_array_get_call ctx (Codegen.AbstractCast.find_array_access_raise ctx a tl ekey None p) c ebase p in
-				let v_get = alloc_var "tmp" e_get.etype in
+				let v_get = alloc_var "tmp" e_get.etype e_get.epos in
 				let ev_get = mk (TLocal v_get) v_get.v_type p in
 				let evar_get = mk (TVar(v_get,Some e_get)) ctx.com.basic.tvoid p in
 				(* op *)
@@ -2511,7 +2511,7 @@ and type_unop ctx op flag e p =
 			error "This kind of operation is not supported" p
 		| AKSet (e,t,cf) ->
 			let l = save_locals ctx in
-			let v = gen_local ctx e.etype in
+			let v = gen_local ctx e.etype p in
 			let ev = mk (TLocal v) e.etype p in
 			let op = (match op with Increment -> OpAdd | Decrement -> OpSub | _ -> assert false) in
 			let one = (EConst (Int "1"),p) in
@@ -2526,7 +2526,7 @@ and type_unop ctx op flag e p =
 					make_call ctx (mk (TField (ev,quick_field_dynamic ev.etype ("set_" ^ cf.cf_name))) (tfun [t] t) p) [get] t p
 				]) t p
 			| Postfix ->
-				let v2 = gen_local ctx t in
+				let v2 = gen_local ctx t p in
 				let ev2 = mk (TLocal v2) t p in
 				let get = type_expr ctx eget Value in
 				let plusone = type_binop ctx op (EConst (Ident v2.v_name),p) one false Value p in
@@ -2595,7 +2595,7 @@ and type_ident ctx i p mode =
 				AKExpr (mk (TConst TThis) ctx.tthis p)
 			else
 				let t = mk_mono() in
-				let v = alloc_unbound_var i t in
+				let v = alloc_unbound_var i t p in
 				AKExpr (mk (TLocal v) t p)
 		end else begin
 			if ctx.curfun = FunStatic && PMap.mem i ctx.curclass.cl_fields then error ("Cannot access " ^ i ^ " in static function") p;
@@ -2604,7 +2604,7 @@ and type_ident ctx i p mode =
 			if ctx.com.display <> DMNone then begin
 				display_error ctx (error_msg err) p;
 				let t = mk_mono() in
-				AKExpr (mk (TLocal (add_local ctx i t)) t p)
+				AKExpr (mk (TLocal (add_local ctx i t p)) t p)
 			end else begin
 				let e = try
 					let t = List.find (fun (i2,_) -> i2 = i) ctx.type_params in
@@ -2752,7 +2752,7 @@ and type_access ctx e p mode =
 				let monos = List.map (fun _ -> mk_mono()) c.cl_params in
 				let ct, cf = get_constructor ctx c monos p in
 				let args = match follow ct with TFun(args,ret) -> args | _ -> assert false in
-				let vl = List.map (fun (n,_,t) -> alloc_var n t) args in
+				let vl = List.map (fun (n,_,t) -> alloc_var n t c.cl_pos) args in
 				let vexpr v = mk (TLocal v) v.v_type p in
 				let el = List.map vexpr vl in
 				let ec,t = match c.cl_kind with
@@ -2831,11 +2831,11 @@ and type_vars ctx vl p =
 					Some e
 			) in
 			if v.[0] = '$' && ctx.com.display = DMNone then error "Variables names starting with a dollar are not allowed" p;
-			add_local ctx v t, e
+			add_local ctx v t p, e (* TODO: var pos *)
 		with
 			Error (e,p) ->
 				display_error ctx (error_msg e) p;
-				add_local ctx v t_dynamic, None
+				add_local ctx v t_dynamic p, None (* TODO: var pos *)
 	) vl in
 	match vl with
 	| [v,eo] ->
@@ -3065,7 +3065,7 @@ and type_object_decl ctx fl with_type p =
 				evars,(s,e) :: elocs,had_side_effect
 			| _ ->
 				if had_side_effect then begin
-					let v = gen_local ctx e.etype in
+					let v = gen_local ctx e.etype e.epos in
 					let ev = mk (TVar(v,Some e)) e.etype e.epos in
 					let eloc = mk (TLocal v) v.v_type e.epos in
 					(ev :: evars),((s,eloc) :: elocs),had_side_effect
@@ -3223,7 +3223,7 @@ and type_try ctx e1 catches with_type p =
 		if v.[0] = '$' then display_error ctx "Catch variable names starting with a dollar are not allowed" p;
 		check_unreachable acc t2 (pos e);
 		let locals = save_locals ctx in
-		let v = add_local ctx v t in
+		let v = add_local ctx v t (pos e) in (* TODO: var pos *)
 		let e = type_expr ctx e with_type in
 		v.v_type <- t2;
 		locals();
@@ -3293,7 +3293,7 @@ and type_map_declaration ctx e1 el with_type p =
 	in
 	let tmap = TAbstract(a,[tkey;tval]) in
 	let cf = PMap.find "set" c.cl_statics in
-	let v = gen_local ctx tmap in
+	let v = gen_local ctx tmap p in
 	let ev = mk (TLocal v) tmap p in
 	let ec = type_module_type ctx (TClassDecl c) None p in
 	let ef = mk (TField(ec,FStatic(c,cf))) (tfun [tkey;tval] ctx.t.tvoid) p in
@@ -3353,7 +3353,7 @@ and type_local_function ctx name f with_type p =
 		| None -> None
 		| Some v ->
 			if v.[0] = '$' then display_error ctx "Variable names starting with a dollar are not allowed" p;
-			Some (add_local ctx v ft)
+			Some (add_local ctx v ft p) (* TODO: var pos *)
 	) in
 	let curfun = match ctx.curfun with
 		| FunStatic -> FunStatic
@@ -3381,7 +3381,7 @@ and type_local_function ctx name f with_type p =
 		let is_rec = (try Filters.local_usage loop e; false with Exit -> true) in
 		let decl = (if is_rec then begin
 			if inline then display_error ctx "Inline function cannot be recursive" e.epos;
-			let vnew = add_local ctx v.v_name ft in
+			let vnew = add_local ctx v.v_name ft v.v_pos in
 			mk (TVar (vnew,Some (mk (TBlock [
 				mk (TVar (v,Some (mk (TConst TNull) ft p))) ctx.t.tvoid p;
 				mk (TBinop (OpAssign,mk (TLocal v) ft p,e)) ft p;
@@ -3476,7 +3476,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| EObjectDecl fl ->
 		type_object_decl ctx fl with_type p
 	| EArrayDecl [(EFor _,_) | (EWhile _,_) as e] ->
-		let v = gen_local ctx (mk_mono()) in
+		let v = gen_local ctx (mk_mono()) p in
 		let et = ref (EConst(Ident "null"),p) in
 		let rec map_compr (e,p) =
 			match e with
@@ -3521,7 +3521,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			| Some e -> e
 			| None ->
 				let t, pt = Typeload.t_iterator ctx in
-				let i = add_local ctx i pt in
+				let i = add_local ctx i pt pi in
 				let e1 = (match follow e1.etype with
 				| TMono _
 				| TDynamic _ ->
@@ -4056,7 +4056,7 @@ and type_call ctx e el (with_type:with_type) p =
 			with Not_found ->
 				e
 			in
-			let v_trace = alloc_unbound_var "`trace" t_dynamic in
+			let v_trace = alloc_unbound_var "`trace" t_dynamic p in
 			mk (TCall (mk (TLocal v_trace) t_dynamic p,[e;infos])) ctx.t.tvoid p
 		else
 			type_expr ctx (ECall ((EField ((EField ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[mk_to_string_meta e;infos]),p) NoValue
@@ -4094,7 +4094,7 @@ and type_call ctx e el (with_type:with_type) p =
 		let e = type_expr ctx e Value in
 		if Common.platform ctx.com Flash then
 			let t = tfun [e.etype] e.etype in
-			let v_unprotect = alloc_unbound_var "__unprotect__" t in
+			let v_unprotect = alloc_unbound_var "__unprotect__" t p in
 			mk (TCall (mk (TLocal v_unprotect) t p,[e])) e.etype e.epos
 		else
 			e