Browse Source

minor

Add position information to:
* complex_type
* most type_path occurrences
* variable names
* function arguments
* catch variable

Support usage,position and type display on type occurrences. Also allow metadata on function arguments.
Simon Krajewski 9 years ago
parent
commit
b56d29a778

+ 16 - 6
src/display/display.ml

@@ -74,6 +74,16 @@ let find_before_pos com e =
 	in
 	map e
 
+let display_type dm t =
+	let mt = module_type_of_type t in
+	match dm with
+	| DMPosition -> raise (DisplayPosition [(t_infos mt).mt_pos]);
+	| DMUsage ->
+		let ti = t_infos mt in
+		ti.mt_meta <- (Meta.Usage,[],ti.mt_pos) :: ti.mt_meta
+	| DMType -> raise (DisplayTypes [t])
+	| _ -> raise Exit
+
 module SymbolKind = struct
 	type t =
 		| File
@@ -174,14 +184,14 @@ let print_document_symbols (pack,decls) =
 				| _ -> ()
 			end *)
 		| EVars vl ->
-			List.iter (fun (s,_,eo) ->
-				add_ignore s Variable p; (* TODO: Don't have a good pos here... *)
+			List.iter (fun ((s,p),_,eo) ->
+				add_ignore s Variable p;
 				expr_opt si eo
 			) vl
 		| ETry(e1,catches) ->
 			expr si e1;
-			List.iter (fun (s,_,e) ->
-				add_ignore s Variable (pos e); (* TODO: No good pos as usual... *)
+			List.iter (fun ((s,p),_,e) ->
+				add_ignore s Variable p;
 				expr si e
 			) catches;
 		| EFunction(Some s,f) ->
@@ -197,8 +207,8 @@ let print_document_symbols (pack,decls) =
 		| None -> ()
 		| Some e -> expr si e
 	and func si f =
-		List.iter (fun (s,_,_,eo) ->
-			let si_arg = add s Variable si.location (* TODO: don't have *) (Some si) in
+		List.iter (fun ((s,p),_,_,_,eo) ->
+			let si_arg = add s Variable p (Some si) in
 			expr_opt (Some si_arg) eo
 		) f.f_args;
 		expr_opt (Some si) f.f_expr

+ 31 - 31
src/generators/gencs.ml

@@ -3502,7 +3502,7 @@ let rec convert_signature ctx p = function
 	| LObject ->
 		mk_type_path ctx ([],[],"Dynamic") []
 	| LPointer s | LManagedPointer s ->
-		mk_type_path ctx (["cs"],[],"Pointer") [ TPType (convert_signature ctx p s) ]
+		mk_type_path ctx (["cs"],[],"Pointer") [ TPType (convert_signature ctx p s,null_pos) ]
 	| LTypedReference ->
 		mk_type_path ctx (["cs";"system"],[],"TypedReference") []
 	| LIntPtr ->
@@ -3510,16 +3510,16 @@ let rec convert_signature ctx p = function
 	| LUIntPtr ->
 		mk_type_path ctx (["cs";"system"],[],"UIntPtr") []
 	| LValueType (s,args) | LClass (s,args) ->
-		mk_type_path ctx s (List.map (fun s -> TPType (convert_signature ctx p s)) args)
+		mk_type_path ctx s (List.map (fun s -> TPType (convert_signature ctx p s,null_pos)) args)
 	| LTypeParam i ->
 		mk_type_path ctx ([],[],"T" ^ string_of_int i) []
 	| LMethodTypeParam i ->
 		mk_type_path ctx ([],[],"M" ^ string_of_int i) []
 	| LVector s ->
-		mk_type_path ctx (["cs"],[],"NativeArray") [TPType (convert_signature ctx p s)]
+		mk_type_path ctx (["cs"],[],"NativeArray") [TPType (convert_signature ctx p s,null_pos)]
 	(* | LArray of ilsig_norm * (int option * int option) array *)
 	| LMethod (_,ret,args) ->
-		CTFunction (List.map (convert_signature ctx p) args, convert_signature ctx p ret)
+		CTFunction (List.map (fun v -> convert_signature ctx p v,null_pos) args, (convert_signature ctx p ret,null_pos))
 	| _ -> mk_type_path ctx ([],[], "Dynamic") []
 
 let ilpath_s = function
@@ -3634,9 +3634,9 @@ let convert_ilfield ctx p field =
 	let kind = match readonly with
 		| true ->
 			cff_meta := (Meta.ReadOnly, [], cff_pos) :: !cff_meta;
-			FProp ("default", "never", Some (convert_signature ctx p field.fsig.snorm), None)
+			FProp ("default", "never", Some (convert_signature ctx p field.fsig.snorm,null_pos), None)
 		| false ->
-			FVar (Some (convert_signature ctx p field.fsig.snorm), None)
+			FVar (Some (convert_signature ctx p field.fsig.snorm,null_pos), None)
 	in
 	let cff_name, cff_meta =
 		if String.get cff_name 0 = '%' then
@@ -3658,7 +3658,7 @@ let convert_ilfield ctx p field =
 let convert_ilevent ctx p ev =
 	let p = { p with pfile =	p.pfile ^" (" ^ev.ename ^")" } in
 	let name = ev.ename in
-	let kind = FVar (Some (convert_signature ctx p ev.esig.snorm), None) in
+	let kind = FVar (Some (convert_signature ctx p ev.esig.snorm,null_pos), None) in
 	let meta = [Meta.Event, [], p; Meta.Keep,[],p; Meta.SkipReflection,[],p] in
 	let acc = [APrivate] in
 	let add_m acc m = match m with
@@ -3767,11 +3767,11 @@ let convert_ilmethod ctx p m is_explicit_impl =
 				| LManagedPointer s ->
 					let is_out = List.mem POut flag.pf_io && not (List.mem PIn flag.pf_io) in
 					let name = if is_out then "Out" else "Ref" in
-					mk_type_path ctx (["cs"],[],name) [ TPType (convert_signature ctx p s) ]
+					mk_type_path ctx (["cs"],[],name) [ TPType (convert_signature ctx p s,null_pos) ]
 				| _ ->
 					convert_signature ctx p (change_sig s.snorm)
 			in
-			name,false,Some t,None) m.margs
+			(name,null_pos),false,[],Some (t,null_pos),None) m.margs
 		in
 		let ret = convert_signature ctx p (change_sig ret) in
 		let types = List.map (fun t ->
@@ -3785,7 +3785,7 @@ let convert_ilmethod ctx p m is_explicit_impl =
 		FFun {
 			f_params = types;
 			f_args = args;
-			f_type = Some ret;
+			f_type = Some (ret,null_pos);
 			f_expr = None;
 		}
 	in
@@ -3870,7 +3870,7 @@ let convert_ilprop ctx p prop is_explicit_impl =
 	in
 
 	let kind =
-		FProp (get, set, Some(convert_signature ctx p ilsig), None)
+		FProp (get, set, Some(convert_signature ctx p ilsig,null_pos), None)
 	in
 	{
 		cff_name = prop.pname;
@@ -3917,13 +3917,13 @@ let mk_abstract_fun name p kind metas acc =
 
 let convert_fun_arg ctx p = function
 	| LManagedPointer s ->
-		mk_type_path ctx (["cs"],[],"Ref") [ TPType (convert_signature ctx p s) ]
+		mk_type_path ctx (["cs"],[],"Ref") [ TPType (convert_signature ctx p s,null_pos) ],p
 	| s ->
-		convert_signature ctx p s
+		convert_signature ctx p s,p
 
 let convert_fun ctx p ret args =
 	let args = List.map (convert_fun_arg ctx p) args in
-	CTFunction(args, convert_signature ctx p ret)
+	CTFunction(args, (convert_signature ctx p ret,null_pos))
 
 let get_clsname ctx cpath =
 	match netpath_to_hx ctx.nstd cpath with
@@ -3938,7 +3938,7 @@ let convert_delegate ctx p ilcls =
 	(* - AsDelegate():Super *)
 	(* - @:op(A+B) Add(d:absType) *)
 	(* - @:op(A-B) Remove(d:absType) *)
-	let abs_type = mk_type_path ctx (ilcls.cpath) (List.map (fun t -> TPType (mk_type_path ctx ([],[],"T" ^ string_of_int t.tnumber) [])) ilcls.ctypes) in
+	let abs_type = mk_type_path ctx (ilcls.cpath) (List.map (fun t -> TPType (mk_type_path ctx ([],[],"T" ^ string_of_int t.tnumber) [],null_pos)) ilcls.ctypes) in
 	let invoke = List.find (fun m -> m.mname = "Invoke") ilcls.cmethods in
 	let ret = invoke.mret.snorm in
 	let args = List.map (fun (_,_,s) -> s.snorm) invoke.margs in
@@ -3959,8 +3959,8 @@ let convert_delegate ctx p ilcls =
 		let expr = (ECall( (EField( (EConst(Ident (clsname)),p), fn_name ),p), [(EConst(Ident"arg1"),p);(EConst(Ident"arg2"),p)]),p) in
 		FFun {
 			f_params = types;
-			f_args = ["arg1",false,Some abs_type,None;"arg2",false,Some abs_type,None];
-			f_type = Some abs_type;
+			f_args = [("arg1",null_pos),false,[],Some (abs_type,null_pos),None;("arg2",null_pos),false,[],Some (abs_type,null_pos),None];
+			f_type = Some (abs_type,null_pos);
 			f_expr = Some ( (EReturn (Some expr), p) );
 		}
 	in
@@ -3976,7 +3976,7 @@ let convert_delegate ctx p ilcls =
 		}
 	in
 	let params = (List.map (fun s ->
-		TPType (mk_type_path ctx ([],[],s.tp_name) [])
+		TPType (mk_type_path ctx ([],[],s.tp_name) [],null_pos)
 	) types) in
 	let underlying_type = match ilcls.cpath with
 		| ns,inner,name ->
@@ -3985,14 +3985,14 @@ let convert_delegate ctx p ilcls =
 
 	let fn_new = FFun {
 		f_params = [];
-		f_args = ["hxfunc",false,Some haxe_type,None];
+		f_args = [("hxfunc",null_pos),false,[],Some (haxe_type,null_pos),None];
 		f_type = None;
 		f_expr = Some ( EBinop(Ast.OpAssign, (EConst(Ident "this"),p), (mk_special_call "__delegate__" p [EConst(Ident "hxfunc"),p]) ), p );
 	} in
 	let fn_from_hx = FFun {
 		f_params = types;
-		f_args = ["hxfunc",false,Some haxe_type,None];
-		f_type = Some( mk_type_path ctx ilcls.cpath params );
+		f_args = [("hxfunc",null_pos),false,[],Some (haxe_type,null_pos),None];
+		f_type = Some( mk_type_path ctx ilcls.cpath params,null_pos );
 		f_expr = Some( EReturn( Some (mk_special_call "__delegate__" p [EConst(Ident "hxfunc"),p] )), p);
 	} in
 	let fn_asdel = FFun {
@@ -4012,7 +4012,7 @@ let convert_delegate ctx p ilcls =
 		d_doc = None;
 		d_params = types;
 		d_meta = mk_metas [Meta.Delegate; Meta.Forward] p;
-		d_flags = [AIsType underlying_type];
+		d_flags = [AIsType (underlying_type,null_pos)];
 		d_data = [fn_new;fn_from_hx;fn_asdel;mk_op Ast.OpAdd "Add";mk_op Ast.OpSub "Remove"];
 	}
 
@@ -4048,12 +4048,12 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 		(match ilcls.csuper with
 			| Some { snorm = LClass ( (["System"],[],"Object"), [] ) } -> ()
 			| Some ({ snorm = LClass ( (["System"],[],"ValueType"), [] ) } as s) ->
-				flags := HExtends (get_type_path ctx (convert_signature ctx p s.snorm)) :: !flags;
+				flags := HExtends (get_type_path ctx (convert_signature ctx p s.snorm),null_pos) :: !flags;
 				meta := (Meta.Struct,[],p) :: !meta
 			| Some { snorm = LClass ( (["haxe";"lang"],[],"HxObject"), [] ) } ->
 				meta := (Meta.HxGen,[],p) :: !meta
 			| Some s ->
-				flags := HExtends (get_type_path ctx (convert_signature ctx p s.snorm)) :: !flags
+				flags := HExtends (get_type_path ctx (convert_signature ctx p s.snorm),null_pos) :: !flags
 			| _ -> ());
 
 			let has_explicit_ifaces = ref false in
@@ -4065,9 +4065,9 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 				| i ->
 					if is_explicit ctx ilcls i then has_explicit_ifaces := true;
 					flags := if !is_interface then
-						HExtends (get_type_path ctx (convert_signature ctx p i)) :: !flags
+						HExtends (get_type_path ctx (convert_signature ctx p i),null_pos) :: !flags
 					else
-						HImplements (get_type_path ctx (convert_signature ctx p i)) :: !flags
+						HImplements (get_type_path ctx (convert_signature ctx p i),null_pos) :: !flags
 			) ilcls.cimplements;
 			(* this is needed because of explicit interfaces. see http://msdn.microsoft.com/en-us/library/aa288461(v=vs.71).aspx *)
 			(* explicit interfaces can't be mapped into Haxe in any way - since their fields can't be accessed directly, but they still implement that interface *)
@@ -4078,9 +4078,9 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 			ignore (List.exists (function
 			| { psig = { snorm = LMethod(_,ret,[v]) } } ->
 				flags := if !is_interface then
-					(HExtends( raw_type_path ctx ([],"ArrayAccess") [ TPType (convert_signature ctx p ret) ]) :: !flags)
+					(HExtends( raw_type_path ctx ([],"ArrayAccess") [ TPType (convert_signature ctx p ret,null_pos) ],null_pos) :: !flags)
 				else
-					(HImplements( raw_type_path ctx ([],"ArrayAccess") [ TPType (convert_signature ctx p ret) ]) :: !flags);
+					(HImplements( raw_type_path ctx ([],"ArrayAccess") [ TPType (convert_signature ctx p ret,null_pos) ],null_pos) :: !flags);
 				true
 			| _ -> false) ilcls.cprops);
 
@@ -4119,7 +4119,7 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 			if delegate then begin
 				(* add op_Addition and op_Subtraction *)
 				let path = ilcls.cpath in
-				let thist = mk_type_path ctx path (List.map (fun t -> TPType (mk_type_path ctx ([],[],"T" ^ string_of_int t.tnumber) [])) ilcls.ctypes) in
+				let thist = mk_type_path ctx path (List.map (fun t -> TPType (mk_type_path ctx ([],[],"T" ^ string_of_int t.tnumber) [],null_pos)) ilcls.ctypes) in
 				let op name =
 					{
 						cff_name = name;
@@ -4129,8 +4129,8 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 						cff_access = [APublic;AStatic];
 						cff_kind = FFun {
 							f_params = params;
-							f_args = ["arg1",false,Some thist,None;"arg2",false,Some thist,None];
-							f_type = Some thist;
+							f_args = [("arg1",null_pos),false,[],Some (thist,null_pos),None;("arg2",null_pos),false,[],Some (thist,null_pos),None];
+							f_type = Some (thist,null_pos);
 							f_expr = None;
 						};
 					}

+ 15 - 15
src/generators/genjava.ml

@@ -2658,8 +2658,8 @@ let has_tparam name params = List.exists(fun (n,_,_) -> n = name) params
 
 let rec convert_arg ctx p arg =
 	match arg with
-	| TAny | TType (WSuper, _) -> TPType (mk_type_path ctx ([], "Dynamic") [])
-	| TType (_, jsig) -> TPType (convert_signature ctx p jsig)
+	| TAny | TType (WSuper, _) -> TPType (mk_type_path ctx ([], "Dynamic") [],null_pos)
+	| TType (_, jsig) -> TPType (convert_signature ctx p jsig,null_pos)
 
 and convert_signature ctx p jsig =
 	match jsig with
@@ -2698,7 +2698,7 @@ and convert_signature ctx p jsig =
 			| _ -> assert false in
 			mk_type_path ctx (pack, name ^ "$" ^ String.concat "$" (List.map fst inners)) (List.map (fun param -> convert_arg ctx p param) actual_param)
 	| TObjectInner (pack, inners) -> assert false
-	| TArray (jsig, _) -> mk_type_path ctx (["java"], "NativeArray") [ TPType (convert_signature ctx p jsig) ]
+	| TArray (jsig, _) -> mk_type_path ctx (["java"], "NativeArray") [ TPType (convert_signature ctx p jsig,null_pos) ]
 	| TMethod _ -> JReader.error "TMethod cannot be converted directly into Complex Type"
 	| TTypeParameter s -> (match ctx.jtparams with
 		| cur :: others ->
@@ -2739,7 +2739,7 @@ let convert_param ctx p parent param =
 		{
 			tp_name = name;
 			tp_params = [];
-			tp_constraints = List.map (convert_signature ctx p) constraints;
+			tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) constraints;
 			tp_meta = [];
 		}
 
@@ -2837,9 +2837,9 @@ let convert_java_enum ctx p pe =
 
 		let kind = match field.jf_kind with
 			| JKField when !readonly ->
-				FProp ("default", "null", Some (convert_signature ctx p field.jf_signature), None)
+				FProp ("default", "null", Some (convert_signature ctx p field.jf_signature,null_pos), None)
 			| JKField ->
-				FVar (Some (convert_signature ctx p field.jf_signature), None)
+				FVar (Some (convert_signature ctx p field.jf_signature,null_pos), None)
 			| JKMethod ->
 				match field.jf_signature with
 				| TMethod (args, ret) ->
@@ -2850,7 +2850,7 @@ let convert_java_enum ctx p pe =
 					let i = ref 0 in
 					let args = List.map (fun s ->
 						incr i;
-						"param" ^ string_of_int !i, false, Some(convert_signature ctx p s), None
+						("param" ^ string_of_int !i,null_pos), false, [], Some(convert_signature ctx p s,null_pos), None
 					) args in
 					let t = Option.map_default (convert_signature ctx p) (mk_type_path ctx ([], "Void") []) ret in
 					cff_meta := (Meta.Overload, [], p) :: !cff_meta;
@@ -2860,14 +2860,14 @@ let convert_java_enum ctx p pe =
 							{
 								tp_name = name;
 								tp_params = [];
-								tp_constraints = List.map (convert_signature ctx p) (ext :: impl);
+								tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) (ext :: impl);
 								tp_meta = [];
 							}
 						| (name, None, impl) ->
 							{
 								tp_name = name;
 								tp_params = [];
-								tp_constraints = List.map (convert_signature ctx p) (impl);
+								tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) (impl);
 								tp_meta = [];
 							}
 					) field.jf_types in
@@ -2876,7 +2876,7 @@ let convert_java_enum ctx p pe =
 					FFun ({
 						f_params = types;
 						f_args = args;
-						f_type = Some t;
+						f_type = Some (t,null_pos);
 						f_expr = None
 					})
 				| _ -> error "Method signature was expected" p
@@ -2965,7 +2965,7 @@ let convert_java_enum ctx p pe =
 			(match jc.csuper with
 				| TObject( (["java";"lang"], "Object"), _ ) -> ()
 				| TObject( (["haxe";"lang"], "HxObject"), _ ) -> meta := (Meta.HxGen,[],p) :: !meta
-				| _ -> flags := HExtends (get_type_path ctx (convert_signature ctx p jc.csuper)) :: !flags
+				| _ -> flags := HExtends (get_type_path ctx (convert_signature ctx p jc.csuper),null_pos) :: !flags
 			);
 
 			List.iter (fun i ->
@@ -2973,9 +2973,9 @@ let convert_java_enum ctx p pe =
 				| TObject ( (["haxe";"lang"], "IHxObject"), _ ) -> meta := (Meta.HxGen,[],p) :: !meta
 				| _ -> flags :=
 					if !is_interface then
-						HExtends (get_type_path ctx (convert_signature ctx p i)) :: !flags
+						HExtends (get_type_path ctx (convert_signature ctx p i),null_pos) :: !flags
 					else
-						HImplements (get_type_path ctx (convert_signature ctx p i)) :: !flags
+						HImplements (get_type_path ctx (convert_signature ctx p i),null_pos) :: !flags
 			) jc.cinterfaces;
 
 			let fields = ref [] in
@@ -3640,10 +3640,10 @@ let add_java_lib com file std =
 																tname = tp.tp_name;
 																tparams = [];
 																tsub = None;
-															})
+															},null_pos)
 														) c.d_params;
 														tsub = Some(c.d_name);
-													};
+													},null_pos;
 												} in
 												inner_alias := SS.add alias_name !inner_alias;
 												alias_list := (alias_def, pos) :: !alias_list;

+ 15 - 15
src/generators/genswf.ml

@@ -49,7 +49,7 @@ let rec make_tpath = function
 		{
 			tpackage = pack;
 			tname = name;
-			tparams = if !pdyn then [TPType (CTPath { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; })] else[];
+			tparams = if !pdyn then [TPType (CTPath { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; },null_pos)] else[];
 			tsub = None;
 		}
 	| HMName (id,ns) ->
@@ -87,11 +87,11 @@ let rec make_tpath = function
 	| HMAny ->
 		assert false
 	| HMParams (t,params) ->
-		let params = List.map (fun t -> TPType (CTPath (make_tpath t))) params in
+		let params = List.map (fun t -> TPType (CTPath (make_tpath t),null_pos)) params in
 		{ (make_tpath t) with tparams = params }
 
 let make_param cl p =
-	{ tpackage = fst cl; tname = snd cl; tparams = [TPType (CTPath { tpackage = fst p; tname = snd p; tparams = []; tsub = None })]; tsub = None }
+	{ tpackage = fst cl; tname = snd cl; tparams = [TPType (CTPath { tpackage = fst p; tname = snd p; tparams = []; tsub = None },null_pos)]; tsub = None }
 
 let make_topt = function
 	| None -> { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None }
@@ -127,7 +127,7 @@ let build_class com c file =
 			d_params = [];
 			d_meta = [];
 			d_flags = [];
-			d_data = CTPath { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; };
+			d_data = CTPath { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; },null_pos;
 		} in
 		(path.tpackage, [(ETypedef inf,pos)])
 	| _ ->
@@ -137,7 +137,7 @@ let build_class com c file =
 	let flags = (match c.hlc_super with
 		| None | Some (HMPath ([],"Object")) -> flags
 		| Some (HMPath ([],"Function")) -> flags (* found in AIR SDK *)
-		| Some s -> HExtends (make_tpath s) :: flags
+		| Some s -> HExtends (make_tpath s,null_pos) :: flags
 	) in
 	let flags = List.map (fun i ->
 		let i = (match i with
@@ -151,9 +151,9 @@ let build_class com c file =
 			| HMPath _ -> i
 			| _ -> assert false
 		) in
-		if c.hlc_interface then HExtends (make_tpath i) else HImplements (make_tpath i)
+		if c.hlc_interface then HExtends (make_tpath i,null_pos) else HImplements (make_tpath i,null_pos)
 	) (Array.to_list c.hlc_implements) @ flags in
-	let flags = if c.hlc_sealed || Common.defined com Define.FlashStrict then flags else HImplements (make_tpath (HMPath ([],"Dynamic"))) :: flags in
+	let flags = if c.hlc_sealed || Common.defined com Define.FlashStrict then flags else HImplements (make_tpath (HMPath ([],"Dynamic")),null_pos) :: flags in
 	(* make fields *)
 	let getters = Hashtbl.create 0 in
 	let setters = Hashtbl.create 0 in
@@ -196,9 +196,9 @@ let build_class com c file =
 		match f.hlf_kind with
 		| HFVar v ->
 			if v.hlv_const then
-				cf.cff_kind <- FProp ("default","never",Some (make_type v.hlv_type),None)
+				cf.cff_kind <- FProp ("default","never",Some (make_type v.hlv_type,null_pos),None)
 			else
-				cf.cff_kind <- FVar (Some (make_dyn_type v.hlv_type),None);
+				cf.cff_kind <- FVar (Some (make_dyn_type v.hlv_type,null_pos),None);
 			cf :: acc
 		| HFMethod m when m.hlm_override ->
 			Hashtbl.add override (name,stat) ();
@@ -249,15 +249,15 @@ let build_class com c file =
 								meta := (Meta.DefParam,[String aname;v]) :: !meta;
 								Some (EConst v,pos)
 					in
-					(aname,!is_opt,Some t,def_val)
+					((aname,null_pos),!is_opt,[],Some (t,null_pos),def_val)
 				) t.hlmt_args in
 				let args = if t.hlmt_var_args then
-					args @ List.map (fun _ -> incr pn; ("p" ^ string_of_int !pn,true,Some (make_type None),None)) [1;2;3;4;5]
+					args @ List.map (fun _ -> incr pn; (("p" ^ string_of_int !pn,null_pos),true,[],Some (make_type None,null_pos),None)) [1;2;3;4;5]
 				else args in
 				let f = {
 					f_params = [];
 					f_args = args;
-					f_type = Some (make_type t.hlmt_ret);
+					f_type = Some (make_type t.hlmt_ret,null_pos);
 					f_expr = None;
 				} in
 				cf.cff_meta <- mk_meta();
@@ -301,7 +301,7 @@ let build_class com c file =
 			cff_doc = None;
 			cff_access = flags;
 			cff_meta = [];
-			cff_kind = if get && set then FVar (Some (make_dyn_type t), None) else FProp ((if get then "default" else "never"),(if set then "default" else "never"),Some (make_dyn_type t),None);
+			cff_kind = if get && set then FVar (Some (make_dyn_type t,null_pos), None) else FProp ((if get then "default" else "never"),(if set then "default" else "never"),Some (make_dyn_type t,null_pos),None);
 		}
 	in
 	let fields = Hashtbl.fold (fun (name,stat) t acc ->
@@ -323,8 +323,8 @@ let build_class com c file =
 			| [] -> []
 			| f :: l ->
 				match f.cff_kind with
-				| FVar (Some (CTPath { tpackage = []; tname = ("String" | "Int" | "UInt") as tname }),None)
-				| FProp ("default","never",Some (CTPath { tpackage = []; tname = ("String" | "Int" | "UInt") as tname }),None) when List.mem AStatic f.cff_access ->
+				| FVar (Some (CTPath { tpackage = []; tname = ("String" | "Int" | "UInt") as tname },null_pos),None)
+				| FProp ("default","never",Some (CTPath { tpackage = []; tname = ("String" | "Int" | "UInt") as tname },null_pos),None) when List.mem AStatic f.cff_access ->
 					if !real_type = "" then real_type := tname else if !real_type <> tname then raise Exit;
 					{
 						ec_name = f.cff_name;

+ 33 - 25
src/macro/interp.ml

@@ -221,8 +221,8 @@ let get_ctx() = (!get_ctx_ref)()
 let enc_array (l:value list) : value = (!enc_array_ref) l
 let dec_array (l:value) : value list = (!dec_array_ref) l
 
-let decode_complex_type (v:value) : Ast.complex_type = (!decode_complex_type_ref) v
-let encode_complex_type (t:Ast.complex_type) : value = (!encode_complex_type_ref) t
+let decode_complex_type (v:value) : Ast.type_hint = (!decode_complex_type_ref) v
+let encode_complex_type (t:Ast.type_hint) : value = (!encode_complex_type_ref) t
 let decode_pos (v:value) : Ast.pos = (!decode_pos_ref) v
 let encode_type (t:Type.t) : value = (!encode_type_ref) t
 let decode_type (v:value) : Type.t = (!decode_type_ref) v
@@ -234,7 +234,7 @@ let encode_clref (c:tclass) : value = (!encode_clref_ref) c
 let enc_hash (h:('a,'b) Hashtbl.t) : value = (!enc_hash_ref) h
 let enc_string (s:string) : value = (!enc_string_ref) s
 let encode_tvar (v:tvar) : value = (!encode_tvar_ref) v
-let decode_path (v:value) : Ast.type_path = (!decode_path_ref) v
+let decode_path (v:value) : Ast.placed_type_path = (!decode_path_ref) v
 let encode_import (i:Ast.import) : value = (!encode_import_ref) i
 let decode_import (v:value) : Ast.import = (!decode_import_ref) v
 
@@ -2451,7 +2451,7 @@ let macro_lib =
 			VString (Digest.to_hex (Digest.string (Marshal.to_string v [Marshal.Closures])))
 		);
 		"to_complex", Fun1 (fun v ->
-			try	encode_complex_type (TExprToExpr.convert_type (decode_type v))
+			try	encode_complex_type (TExprToExpr.convert_type' (decode_type v))
 			with Exit -> VNull
 		);
 		"unify", Fun2 (fun t1 t2 ->
@@ -2466,7 +2466,7 @@ let macro_lib =
 			encode_texpr ((get_ctx()).curapi.type_expr (decode_expr v))
 		);
 		"resolve_type", Fun2 (fun t p ->
-			encode_type ((get_ctx()).curapi.resolve_type (decode_complex_type t) (decode_pos p));
+			encode_type ((get_ctx()).curapi.resolve_type (fst (decode_complex_type t)) (decode_pos p));
 		);
 		"s_type", Fun1 (fun v ->
 			VString (Type.s_type (print_context()) (decode_type v))
@@ -2646,7 +2646,7 @@ let macro_lib =
 		"define_module", Fun4 (fun p v i u ->
 			match p, v, i, u with
 			| VString path, VArray vl, VArray ui, VArray ul ->
-				(get_ctx()).curapi.define_module path (Array.to_list vl) (List.map decode_import (Array.to_list ui)) (List.map decode_path (Array.to_list ul));
+				(get_ctx()).curapi.define_module path (Array.to_list vl) (List.map decode_import (Array.to_list ui)) (List.map fst (List.map decode_path (Array.to_list ul)));
 				VNull
 			| _ ->
 				error()
@@ -3940,7 +3940,10 @@ let encode_import (path,mode) =
 		"mode", mode
 	]
 
-let rec encode_path t =
+let encode_placed_name (s,p) =
+	enc_string s
+
+let rec encode_path (t,_) =
 	let fields = [
 		"pack", enc_array (List.map enc_string t.tpackage);
 		"name", enc_string t.tname;
@@ -3992,9 +3995,9 @@ and encode_field (f:class_field) =
 	]
 
 and encode_ctype t =
-	let tag, pl = match t with
+	let tag, pl = match fst t with
 	| CTPath p ->
-		0, [encode_path p]
+		0, [encode_path (p,null_pos)]
 	| CTFunction (pl,r) ->
 		1, [enc_array (List.map encode_ctype pl);encode_ctype r]
 	| CTAnonymous fl ->
@@ -4019,10 +4022,11 @@ and encode_tparam_decl tp =
 and encode_fun f =
 	enc_obj [
 		"params", enc_array (List.map encode_tparam_decl f.f_params);
-		"args", enc_array (List.map (fun (n,opt,t,e) ->
+		"args", enc_array (List.map (fun (n,opt,m,t,e) ->
 			enc_obj [
-				"name", enc_string n;
+				"name", encode_placed_name n;
 				"opt", VBool opt;
+				(* "meta", encode_meta_content m; *)
 				"type", null encode_ctype t;
 				"value", null encode_expr e;
 			]
@@ -4060,7 +4064,7 @@ and encode_expr e =
 			| EVars vl ->
 				10, [enc_array (List.map (fun (v,t,eo) ->
 					enc_obj [
-						"name",enc_string v;
+						"name",encode_placed_name v;
 						"type",null encode_ctype t;
 						"expr",null loop eo;
 					]
@@ -4088,7 +4092,7 @@ and encode_expr e =
 			| ETry (e,catches) ->
 				18, [loop e;enc_array (List.map (fun (v,t,e) ->
 					enc_obj [
-						"name",enc_string v;
+						"name",encode_placed_name v;
 						"type",encode_ctype t;
 						"expr",loop e
 					]
@@ -4227,13 +4231,16 @@ let decode_import_mode t =
 
 let decode_import t = (List.map (fun o -> ((dec_string (field o "name")), (decode_pos (field o "pos")))) (dec_array (field t "path")), decode_import_mode (field t "mode"))
 
+let decode_placed_name v =
+	dec_string v,null_pos
+
 let rec decode_path t =
 	{
 		tpackage = List.map dec_string (dec_array (field t "pack"));
 		tname = dec_string (field t "name");
 		tparams = (match field t "params" with VNull -> [] | a -> List.map decode_tparam (dec_array a));
 		tsub = opt dec_string (field t "sub");
-	}
+	},null_pos
 
 and decode_tparam v =
 	match decode_enum v with
@@ -4257,7 +4264,7 @@ and decode_fun v =
 	{
 		f_params = decode_tparams (field v "params");
 		f_args = List.map (fun o ->
-			(dec_string (field o "name"),(match field o "opt" with VNull -> false | v -> dec_bool v),opt decode_ctype (field o "type"),opt decode_expr (field o "value"))
+			(decode_placed_name (field o "name"),(match field o "opt" with VNull -> false | v -> dec_bool v),[],opt decode_ctype (field o "type"),opt decode_expr (field o "value")) (* TODO meta *)
 		) (dec_array (field v "args"));
 		f_type = opt decode_ctype (field v "ret");
 		f_expr = opt decode_expr (field v "expr");
@@ -4302,9 +4309,9 @@ and decode_field v =
 	}
 
 and decode_ctype t =
-	match decode_enum t with
+	(match decode_enum t with
 	| 0, [p] ->
-		CTPath (decode_path p)
+		CTPath (fst (decode_path p))
 	| 1, [a;r] ->
 		CTFunction (List.map decode_ctype (dec_array a), decode_ctype r)
 	| 2, [fl] ->
@@ -4316,12 +4323,13 @@ and decode_ctype t =
 	| 5, [t] ->
 		CTOptional (decode_ctype t)
 	| _ ->
-		raise Invalid_expr
+		raise Invalid_expr),null_pos
 
 let rec decode_expr v =
 	let rec loop v =
-		(decode (field v "expr"), decode_pos (field v "pos"))
-	and decode e =
+		let p = decode_pos (field v "pos") in
+		(decode (field v "expr") p, p)
+	and decode e p =
 		match decode_enum e with
 		| 0, [c] ->
 			EConst (decode_const c)
@@ -4347,7 +4355,7 @@ let rec decode_expr v =
 			EUnop (decode_unop op,(if f then Postfix else Prefix),loop e)
 		| 10, [vl] ->
 			EVars (List.map (fun v ->
-				(dec_string (field v "name"),opt decode_ctype (field v "type"),opt loop (field v "expr"))
+				((dec_string (field v "name"),p),opt decode_ctype (field v "type"),opt loop (field v "expr"))
 			) (dec_array vl))
 		| 11, [fname;f] ->
 			EFunction (opt dec_string fname,decode_fun f)
@@ -4368,7 +4376,7 @@ let rec decode_expr v =
 			ESwitch (loop e,cases,opt decode_null_expr eo)
 		| 18, [e;catches] ->
 			let catches = List.map (fun c ->
-				(dec_string (field c "name"),decode_ctype (field c "type"),loop (field c "expr"))
+				((dec_string (field c "name"),p),(decode_ctype (field c "type")),loop (field c "expr"))
 			) (dec_array catches) in
 			ETry (loop e, catches)
 		| 19, [e] ->
@@ -4390,7 +4398,7 @@ let rec decode_expr v =
 		| 27, [e1;e2;e3] ->
 			ETernary (loop e1,loop e2,loop e3)
 		| 28, [e;t] ->
-			ECheckType (loop e, decode_ctype t)
+			ECheckType (loop e, (decode_ctype t))
 		| 29, [m;e] ->
 			EMeta (decode_meta_entry m,loop e)
 		| 30, [e;f] ->
@@ -5001,7 +5009,7 @@ let decode_type_def v =
 	let tdef = (match decode_enum (field v "kind") with
 	| 0, [] ->
 		let conv f =
-			let loop (n,opt,t,_) =
+			let loop ((n,_),opt,_,t,_) =
 				match t with
 				| None -> raise Invalid_expr
 				| Some t -> n, opt, t
@@ -5023,7 +5031,7 @@ let decode_type_def v =
 		in
 		EEnum (mk (if isExtern then [EExtern] else []) (List.map conv fields))
 	| 1, [] ->
-		ETypedef (mk (if isExtern then [EExtern] else []) (CTAnonymous fields))
+		ETypedef (mk (if isExtern then [EExtern] else []) (CTAnonymous fields,null_pos))
 	| 2, [ext;impl;interf] ->
 		let flags = if isExtern then [HExtern] else [] in
 		let flags = (match interf with VNull | VBool false -> flags | VBool true -> HInterface :: flags | _ -> raise Invalid_expr) in

+ 10 - 10
src/optimization/optimizer.ml

@@ -1652,10 +1652,10 @@ let optimize_completion_expr e =
 				());
 			map e
 		| EVars vl ->
-			let vl = List.map (fun (v,t,e) ->
+			let vl = List.map (fun ((v,pv),t,e) ->
 				let e = (match e with None -> None | Some e -> Some (loop e)) in
-				decl v t e;
-				(v,t,e)
+				decl v (Option.map fst t) e;
+				((v,pv),t,e)
 			) vl in
 			(EVars vl,p)
 		| EBlock el ->
@@ -1675,7 +1675,7 @@ let optimize_completion_expr e =
 			| Some name ->
 				decl name None (Some e));
 			let old = save() in
-			List.iter (fun (n,_,t,e) -> decl n t e) f.f_args;
+			List.iter (fun ((n,_),_,_,t,e) -> decl n (Option.map fst t) e) f.f_args;
 			let e = map e in
 			old();
 			e
@@ -1684,7 +1684,7 @@ let optimize_completion_expr e =
 			let old = save() in
 			let etmp = (EConst (Ident "$tmp"),p) in
 			decl n None (Some (EBlock [
-				(EVars ["$tmp",None,None],p);
+				(EVars [("$tmp",null_pos),None,None],p);
 				(EFor ((EIn (id,it),p),(EBinop (OpAssign,etmp,(EConst (Ident n),p)),p)),p);
 				etmp
 			],p));
@@ -1724,12 +1724,12 @@ let optimize_completion_expr e =
 			(ESwitch (e,cases,def),p)
 		| ETry (et,cl) ->
 			let et = loop et in
-			let cl = List.map (fun (n,t,e) ->
+			let cl = List.map (fun ((n,pn),(t,pt),e) ->
 				let old = save() in
 				decl n (Some t) None;
 				let e = loop e in
 				old();
-				n, t, e
+				(n,pn), (t,pt), e
 			) cl in
 			(ETry (et,cl),p)
 		| EDisplay (s,call) ->
@@ -1742,14 +1742,14 @@ let optimize_completion_expr e =
 					let p = snd e in
 					(try
 						(match PMap.find n locals.r with
-						| Some t , _ -> (ECheckType ((EConst (Ident "null"),p),t),p)
+						| Some t , _ -> (ECheckType ((EConst (Ident "null"),p),(t,p)),p)
 						| _, Some (id,e,lc) ->
 							let name = (try
 								PMap.find id (!tmp_hlocals)
 							with Not_found ->
 								let e = subst_locals lc e in
 								let name = "$tmp_" ^ string_of_int id in
-								tmp_locals := (name,None,Some e) :: !tmp_locals;
+								tmp_locals := ((name,null_pos),None,Some e) :: !tmp_locals;
 								tmp_hlocals := PMap.add id name !tmp_hlocals;
 								name
 							) in
@@ -1761,7 +1761,7 @@ let optimize_completion_expr e =
 						(* not found locals are most likely to be member/static vars *)
 						e)
 				| EFunction (_,f) ->
-					Ast.map_expr (subst_locals { r = PMap.foldi (fun n i acc -> if List.exists (fun (a,_,_,_) -> a = n) f.f_args then acc else PMap.add n i acc) locals.r PMap.empty }) e
+					Ast.map_expr (subst_locals { r = PMap.foldi (fun n i acc -> if List.exists (fun ((a,_),_,_,_,_) -> a = n) f.f_args then acc else PMap.add n i acc) locals.r PMap.empty }) e
 				| EObjectDecl [] ->
 					(* this probably comes from { | completion so we need some context} *)
 					raise Exit

+ 69 - 63
src/syntax/ast.ml

@@ -319,25 +319,31 @@ type type_path = {
 	tsub : string option;
 }
 
+and placed_type_path = type_path * pos
+
 and type_param_or_const =
-	| TPType of complex_type
+	| TPType of type_hint
 	| TPExpr of expr
 
 and complex_type =
 	| CTPath of type_path
-	| CTFunction of complex_type list * complex_type
+	| CTFunction of type_hint list * type_hint
 	| CTAnonymous of class_field list
-	| CTParent of complex_type
-	| CTExtend of type_path list * class_field list
-	| CTOptional of complex_type
+	| CTParent of type_hint
+	| CTExtend of placed_type_path list * class_field list
+	| CTOptional of type_hint
+
+and type_hint = complex_type * pos
 
 and func = {
 	f_params : type_param list;
-	f_args : (string * bool * complex_type option * expr option) list;
-	f_type : complex_type option;
+	f_args : (placed_name * bool * metadata * type_hint option * expr option) list;
+	f_type : type_hint option;
 	f_expr : expr option;
 }
 
+and placed_name = string * pos
+
 and expr_def =
 	| EConst of constant
 	| EArray of expr * expr
@@ -347,9 +353,9 @@ and expr_def =
 	| EObjectDecl of (string * expr) list
 	| EArrayDecl of expr list
 	| ECall of expr * expr list
-	| ENew of type_path * expr list
+	| ENew of placed_type_path * expr list
 	| EUnop of unop * unop_flag * expr
-	| EVars of (string * complex_type option * expr option) list
+	| EVars of (placed_name * type_hint option * expr option) list
 	| EFunction of string option * func
 	| EBlock of expr list
 	| EFor of expr * expr
@@ -357,17 +363,17 @@ and expr_def =
 	| EIf of expr * expr * expr option
 	| EWhile of expr * expr * while_flag
 	| ESwitch of expr * (expr list * expr option * expr option) list * expr option option
-	| ETry of expr * (string * complex_type * expr) list
+	| ETry of expr * (placed_name * type_hint * expr) list
 	| EReturn of expr option
 	| EBreak
 	| EContinue
 	| EUntyped of expr
 	| EThrow of expr
-	| ECast of expr * complex_type option
+	| ECast of expr * type_hint option
 	| EDisplay of expr * bool
-	| EDisplayNew of type_path
+	| EDisplayNew of placed_type_path
 	| ETernary of expr * expr * expr
-	| ECheckType of expr * complex_type
+	| ECheckType of expr * type_hint
 	| EMeta of metadata_entry * expr
 
 and expr = expr_def * pos
@@ -375,7 +381,7 @@ and expr = expr_def * pos
 and type_param = {
 	tp_name : string;
 	tp_params :	type_param list;
-	tp_constraints : complex_type list;
+	tp_constraints : type_hint list;
 	tp_meta : metadata;
 }
 
@@ -394,9 +400,9 @@ and access =
 	| AMacro
 
 and class_field_kind =
-	| FVar of complex_type option * expr option
+	| FVar of type_hint option * expr option
 	| FFun of func
-	| FProp of string * string * complex_type option * expr option
+	| FProp of string * string * type_hint option * expr option
 
 and class_field = {
 	cff_name : string;
@@ -415,24 +421,24 @@ type class_flag =
 	| HInterface
 	| HExtern
 	| HPrivate
-	| HExtends of type_path
-	| HImplements of type_path
+	| HExtends of placed_type_path
+	| HImplements of placed_type_path
 
 type abstract_flag =
 	| APrivAbstract
-	| AFromType of complex_type
-	| AToType of complex_type
-	| AIsType of complex_type
+	| AFromType of type_hint
+	| AToType of type_hint
+	| AIsType of type_hint
 	| AExtern
 
 type enum_constructor = {
 	ec_name : string;
 	ec_doc : documentation;
 	ec_meta : metadata;
-	ec_args : (string * bool * complex_type) list;
+	ec_args : (string * bool * type_hint) list;
 	ec_pos : pos;
 	ec_params : type_param list;
-	ec_type : complex_type option;
+	ec_type : type_hint option;
 }
 
 type ('a,'b) definition = {
@@ -454,10 +460,10 @@ type import = (string * pos) list * import_mode
 type type_def =
 	| EClass of (class_flag, class_field list) definition
 	| EEnum of (enum_flag, enum_constructor list) definition
-	| ETypedef of (enum_flag, complex_type) definition
+	| ETypedef of (enum_flag, type_hint) definition
 	| EAbstract of (abstract_flag, class_field list) definition
 	| EImport of import
-	| EUsing of type_path
+	| EUsing of placed_type_path
 
 type type_decl = type_def * pos
 
@@ -701,31 +707,31 @@ let map_expr loop (e,p) =
 		match o with None -> None | Some v -> Some (f v)
 	in
 	let rec tparam = function
-		| TPType t -> TPType (ctype t)
+		| TPType t -> TPType (type_hint t)
 		| TPExpr e -> TPExpr (loop e)
 	and cfield f =
 		{ f with cff_kind = (match f.cff_kind with
-			| FVar (t,e) -> FVar (opt ctype t, opt loop e)
+			| FVar (t,e) -> FVar (opt type_hint t, opt loop e)
 			| FFun f -> FFun (func f)
-			| FProp (get,set,t,e) -> FProp (get,set,opt ctype t,opt loop e))
+			| FProp (get,set,t,e) -> FProp (get,set,opt type_hint t,opt loop e))
 		}
-	and ctype = function
-		| CTPath t -> CTPath (tpath t)
-		| CTFunction (cl,c) -> CTFunction (List.map ctype cl, ctype c)
+	and type_hint (t,p) = (match t with
+		| CTPath t -> CTPath { t with tparams = List.map tparam t.tparams }
+		| CTFunction (cl,c) -> CTFunction (List.map type_hint cl, type_hint c)
 		| CTAnonymous fl -> CTAnonymous (List.map cfield fl)
-		| CTParent t -> CTParent (ctype t)
+		| CTParent t -> CTParent (type_hint t)
 		| CTExtend (tl,fl) -> CTExtend (List.map tpath tl, List.map cfield fl)
-		| CTOptional t -> CTOptional (ctype t)
+		| CTOptional t -> CTOptional (type_hint t)),p
 	and tparamdecl t =
-		{ tp_name = t.tp_name; tp_constraints = List.map ctype t.tp_constraints; tp_params = List.map tparamdecl t.tp_params; tp_meta = t.tp_meta }
+		{ tp_name = t.tp_name; tp_constraints = List.map type_hint t.tp_constraints; tp_params = List.map tparamdecl t.tp_params; tp_meta = t.tp_meta }
 	and func f =
 		{
 			f_params = List.map tparamdecl f.f_params;
-			f_args = List.map (fun (n,o,t,e) -> n,o,opt ctype t,opt loop e) f.f_args;
-			f_type = opt ctype f.f_type;
+			f_args = List.map (fun (n,o,m,t,e) -> n,o,m,opt type_hint t,opt loop e) f.f_args;
+			f_type = opt type_hint f.f_type;
 			f_expr = opt loop f.f_expr;
 		}
-	and tpath t = { t with tparams = List.map tparam t.tparams }
+	and tpath (t,p) = { t with tparams = List.map tparam t.tparams },p
 	in
 	let e = (match e with
 	| EConst _ -> e
@@ -738,7 +744,7 @@ let map_expr loop (e,p) =
 	| ECall (e,el) -> ECall (loop e, List.map loop el)
 	| ENew (t,el) -> ENew (tpath t,List.map loop el)
 	| EUnop (op,f,e) -> EUnop (op,f,loop e)
-	| EVars vl -> EVars (List.map (fun (n,t,eo) -> n,opt ctype t,opt loop eo) vl)
+	| EVars vl -> EVars (List.map (fun (n,t,eo) -> n,opt type_hint t,opt loop eo) vl)
 	| EFunction (n,f) -> EFunction (n,func f)
 	| EBlock el -> EBlock (List.map loop el)
 	| EFor (e1,e2) -> EFor (loop e1, loop e2)
@@ -746,17 +752,17 @@ let map_expr loop (e,p) =
 	| EIf (e,e1,e2) -> EIf (loop e, loop e1, opt loop e2)
 	| EWhile (econd,e,f) -> EWhile (loop econd, loop e, f)
 	| ESwitch (e,cases,def) -> ESwitch (loop e, List.map (fun (el,eg,e) -> List.map loop el, opt loop eg, opt loop e) cases, opt (opt loop) def)
-	| ETry (e,catches) -> ETry (loop e, List.map (fun (n,t,e) -> n,ctype t,loop e) catches)
+	| ETry (e,catches) -> ETry (loop e, List.map (fun (n,t,e) -> n,type_hint t,loop e) catches)
 	| EReturn e -> EReturn (opt loop e)
 	| EBreak -> EBreak
 	| EContinue -> EContinue
 	| EUntyped e -> EUntyped (loop e)
 	| EThrow e -> EThrow (loop e)
-	| ECast (e,t) -> ECast (loop e,opt ctype t)
+	| ECast (e,t) -> ECast (loop e,opt type_hint t)
 	| EDisplay (e,f) -> EDisplay (loop e,f)
 	| EDisplayNew t -> EDisplayNew (tpath t)
 	| ETernary (e1,e2,e3) -> ETernary (loop e1,loop e2,loop e3)
-	| ECheckType (e,t) -> ECheckType (loop e, ctype t)
+	| ECheckType (e,t) -> ECheckType (loop e, type_hint t)
 	| EMeta (m,e) -> EMeta(m, loop e)
 	) in
 	(e,p)
@@ -785,7 +791,7 @@ let iter_expr loop (e,p) =
 		) cases;
 		(match def with None -> () | Some e -> opt e);
 	| EFunction(_,f) ->
-		List.iter (fun (_,_,_,eo) -> opt eo) f.f_args;
+		List.iter (fun (_,_,_,_,eo) -> opt eo) f.f_args;
 		opt f.f_expr
 	| EVars vl -> List.iter (fun (_,_,eo) -> opt eo) vl
 
@@ -823,15 +829,15 @@ let s_expr e =
 		| EContinue -> "continue"
 		| EUntyped e -> "untyped " ^ s_expr_inner tabs e
 		| EThrow e -> "throw " ^ s_expr_inner tabs e
-		| ECast (e,Some t) -> "cast (" ^ s_expr_inner tabs e ^ ", " ^ s_complex_type tabs t ^ ")"
+		| ECast (e,Some (t,_)) -> "cast (" ^ s_expr_inner tabs e ^ ", " ^ s_complex_type tabs t ^ ")"
 		| ECast (e,None) -> "cast " ^ s_expr_inner tabs e
 		| ETernary (e1,e2,e3) -> s_expr_inner tabs e1 ^ " ? " ^ s_expr_inner tabs e2 ^ " : " ^ s_expr_inner tabs e3
-		| ECheckType (e,t) -> "(" ^ s_expr_inner tabs e ^ " : " ^ s_complex_type tabs t ^ ")"
+		| ECheckType (e,(t,_)) -> "(" ^ s_expr_inner tabs e ^ " : " ^ s_complex_type tabs t ^ ")"
 		| EMeta (m,e) -> s_metadata tabs m ^ " " ^ s_expr_inner tabs e
 		| _ -> ""
 	and s_expr_list tabs el sep =
 		(String.concat sep (List.map (s_expr_inner tabs) el))
-	and s_complex_type_path tabs t =
+	and s_complex_type_path tabs (t,_) =
 		(String.concat "." t.tpackage) ^ if List.length t.tpackage > 0 then "." else "" ^
 		t.tname ^
 		match t.tsub with
@@ -844,15 +850,15 @@ let s_expr e =
 		else ""
 	and s_type_param_or_const tabs p =
 		match p with
-		| TPType t -> s_complex_type tabs t
+		| TPType (t,_) -> s_complex_type tabs t
 		| TPExpr e -> s_expr_inner tabs e
 	and s_complex_type tabs ct =
 		match ct with
-		| CTPath t -> s_complex_type_path tabs t
-		| CTFunction (cl,c) -> if List.length cl > 0 then String.concat " -> " (List.map (s_complex_type tabs) cl) else "Void" ^ " -> " ^ s_complex_type tabs c
+		| CTPath t -> s_complex_type_path tabs (t,null_pos)
+		| CTFunction (cl,(c,_)) -> if List.length cl > 0 then String.concat " -> " (List.map (fun (t,_) -> s_complex_type tabs t) cl) else "Void" ^ " -> " ^ s_complex_type tabs c
 		| CTAnonymous fl -> "{ " ^ String.concat "; " (List.map (s_class_field tabs) fl) ^ "}";
-		| CTParent t -> "(" ^ s_complex_type tabs t ^ ")"
-		| CTOptional t -> "?" ^ s_complex_type tabs t
+		| CTParent(t,_) -> "(" ^ s_complex_type tabs t ^ ")"
+		| CTOptional(t,_) -> "?" ^ s_complex_type tabs t
 		| CTExtend (tl, fl) -> "{> " ^ String.concat " >, " (List.map (s_complex_type_path tabs) tl) ^ ", " ^ String.concat ", " (List.map (s_class_field tabs) fl) ^ " }"
 	and s_class_field tabs f =
 		match f.cff_doc with
@@ -861,38 +867,38 @@ let s_expr e =
 		if List.length f.cff_meta > 0 then String.concat ("\n" ^ tabs) (List.map (s_metadata tabs) f.cff_meta) else "" ^
 		if List.length f.cff_access > 0 then String.concat " " (List.map s_access f.cff_access) else "" ^
 		match f.cff_kind with
-		| FVar (t,e) -> "var " ^ f.cff_name ^ s_opt_complex_type tabs t " : " ^ s_opt_expr tabs e " = "
-		| FProp (get,set,t,e) -> "var " ^ f.cff_name ^ "(" ^ get ^ "," ^ set ^ ")" ^ s_opt_complex_type tabs t " : " ^ s_opt_expr tabs e " = "
+		| FVar (t,e) -> "var " ^ f.cff_name ^ s_opt_type_hint tabs t " : " ^ s_opt_expr tabs e " = "
+		| FProp (get,set,t,e) -> "var " ^ f.cff_name ^ "(" ^ get ^ "," ^ set ^ ")" ^ s_opt_type_hint tabs t " : " ^ s_opt_expr tabs e " = "
 		| FFun func -> "function " ^ f.cff_name ^ s_func tabs func
 	and s_metadata tabs (s,e,_) =
 		"@" ^ Meta.to_string s ^ if List.length e > 0 then "(" ^ s_expr_list tabs e ", " ^ ")" else ""
-	and s_opt_complex_type tabs t pre =
-		match t with
-		| Some s -> pre ^ s_complex_type tabs s
-		| None -> ""
 	and s_opt_expr tabs e pre =
 		match e with
 		| Some s -> pre ^ s_expr_inner tabs s
 		| None -> ""
+	and s_opt_type_hint tabs t pre =
+		match t with
+		| Some(t,_) -> pre ^ s_complex_type tabs t
+		| None -> ""
 	and s_func tabs f =
 		s_type_param_list tabs f.f_params ^
 		"(" ^ String.concat ", " (List.map (s_func_arg tabs) f.f_args) ^ ")" ^
-		s_opt_complex_type tabs f.f_type ":" ^
+		s_opt_type_hint tabs f.f_type ":" ^
 		s_opt_expr tabs f.f_expr " "
 	and s_type_param tabs t =
 		t.tp_name ^ s_type_param_list tabs t.tp_params ^
-		if List.length t.tp_constraints > 0 then ":(" ^ String.concat ", " (List.map (s_complex_type tabs) t.tp_constraints) ^ ")" else ""
+		if List.length t.tp_constraints > 0 then ":(" ^ String.concat ", " (List.map ((fun (t,_) -> s_complex_type tabs t)) t.tp_constraints) ^ ")" else ""
 	and s_type_param_list tabs tl =
 		if List.length tl > 0 then "<" ^ String.concat ", " (List.map (s_type_param tabs) tl) ^ ">" else ""
-	and s_func_arg tabs (n,o,t,e) =
-		if o then "?" else "" ^ n ^ s_opt_complex_type tabs t ":" ^ s_opt_expr tabs e " = "
-	and s_var tabs (n,t,e) =
-		n ^ s_opt_complex_type tabs t ":" ^ s_opt_expr tabs e " = "
+	and s_func_arg tabs ((n,_),o,_,t,e) =
+		if o then "?" else "" ^ n ^ s_opt_type_hint tabs t ":" ^ s_opt_expr tabs e " = "
+	and s_var tabs ((n,_),t,e) =
+		n ^ (s_opt_type_hint tabs t ":") ^ s_opt_expr tabs e " = "
 	and s_case tabs (el,e1,e2) =
 		"case " ^ s_expr_list tabs el ", " ^
 		(match e1 with None -> ":" | Some e -> " if (" ^ s_expr_inner tabs e ^ "):") ^
 		(match e2 with None -> "" | Some e -> s_expr_omit_block tabs e)
-	and s_catch tabs (n,t,e) =
+	and s_catch tabs ((n,_),(t,_),e) =
 		" catch(" ^ n ^ ":" ^ s_complex_type tabs t ^ ") " ^ s_expr_inner tabs e
 	and s_block tabs el opn nl cls =
 		 opn ^ "\n\t" ^ tabs ^ (s_expr_list (tabs ^ "\t") el (";\n\t" ^ tabs)) ^ ";" ^ nl ^ tabs ^ cls

+ 89 - 80
src/syntax/parser.ml

@@ -150,7 +150,7 @@ let rec make_meta name params ((v,p2) as e) p1 =
 	| ETernary (e1,e2,e3) -> ETernary (make_meta name params e1 p1 , e2, e3), punion p1 p2
 	| _ -> EMeta((name,params,p1),e),punion p1 p2
 
-let make_is e t p =
+let make_is e (t,_) p =
 	let e_is = EField((EConst(Ident "Std"),p),"is"),p in
 	let e2 = expr_of_type_path (t.tpackage,t.tname) p in
 	ECall(e_is,[e;e2]),p
@@ -229,7 +229,7 @@ let reify in_macro =
 			| TPExpr e -> "TPExpr", to_expr e p
 		) in
 		mk_enum "TypeParam" n [v] p
-	and to_tpath t p =
+	and to_tpath (t,_) p =
 		let len = String.length t.tname in
 		if t.tpackage = [] && len > 1 && t.tname.[0] = '$' then
 			(EConst (Ident (String.sub t.tname 1 (len - 1))),p)
@@ -243,21 +243,24 @@ let reify in_macro =
 		end
 	and to_ctype t p =
 		let ct n vl = mk_enum "ComplexType" n vl p in
-		match t with
-		| CTPath { tpackage = []; tparams = []; tsub = None; tname = n } when n.[0] = '$' ->
+		match fst t with
+		| CTPath ({ tpackage = []; tparams = []; tsub = None; tname = n }) when n.[0] = '$' ->
 			to_string n p
-		| CTPath t -> ct "TPath" [to_tpath t p]
-		| CTFunction (args,ret) -> ct "TFunction" [to_array to_ctype args p; to_ctype ret p]
+		| CTPath t -> ct "TPath" [to_tpath (t,p) p]
+		| CTFunction (args,ret) -> ct "TFunction" [to_array to_type_hint args p; to_type_hint ret p]
 		| CTAnonymous fields -> ct "TAnonymous" [to_array to_cfield fields p]
-		| CTParent t -> ct "TParent" [to_ctype t p]
+		| CTParent t -> ct "TParent" [to_type_hint t p]
 		| CTExtend (tl,fields) -> ct "TExtend" [to_array to_tpath tl p; to_array to_cfield fields p]
-		| CTOptional t -> ct "TOptional" [to_ctype t p]
+		| CTOptional t -> ct "TOptional" [to_type_hint t p]
+	and to_type_hint (t,p) _ =
+		(* to_obj ["type",to_ctype t p;"pos",to_pos p] p *)
+		to_ctype (t,p) p
 	and to_fun f p =
-		let farg (n,o,t,e) p =
+		let farg ((n,_),o,_,t,e) p =
 			let fields = [
 				"name", to_string n p;
 				"opt", to_bool o p;
-				"type", to_opt to_ctype t p;
+				"type", to_opt to_type_hint t p;
 			] in
 			to_obj (match e with None -> fields | Some e -> fields @ ["value",to_expr e p]) p
 		in
@@ -271,7 +274,7 @@ let reify in_macro =
 		in
 		let fields = [
 			("args",to_array farg f.f_args p);
-			("ret",to_opt to_ctype f.f_type p);
+			("ret",to_opt to_type_hint f.f_type p);
 			("expr",to_opt to_expr f.f_expr p);
 			("params",to_array fparam f.f_params p);
 		] in
@@ -292,9 +295,9 @@ let reify in_macro =
 		in
 		let to_kind k =
 			let n, vl = (match k with
-				| FVar (ct,e) -> "FVar", [to_opt to_ctype ct p;to_opt to_expr e p]
+				| FVar (ct,e) -> "FVar", [to_opt to_type_hint ct p;to_opt to_expr e p]
 				| FFun f -> "FFun", [to_fun f p]
-				| FProp (get,set,t,e) -> "FProp", [to_string get p; to_string set p; to_opt to_ctype t p; to_opt to_expr e p]
+				| FProp (get,set,t,e) -> "FProp", [to_string get p; to_string set p; to_opt to_type_hint t p; to_opt to_expr e p]
 			) in
 			mk_enum "FieldType" n vl p
 		in
@@ -370,10 +373,11 @@ let reify in_macro =
 			) [] p in
 			expr "EUnop" [op;to_bool (flag = Postfix) p;loop e]
 		| EVars vl ->
-			expr "EVars" [to_array (fun (v,t,e) p ->
+			expr "EVars" [to_array (fun ((n,pn),th,e) p ->
 				let fields = [
-					"name", to_string v p;
-					"type", to_opt to_ctype t p;
+					(* "name", to_obj ["name",to_string n pn;"pos",to_pos pn] p; *)
+					"name", to_string n pn;
+					"type", to_opt to_type_hint th p;
 					"expr", to_opt to_expr e p;
 				] in
 				to_obj fields p
@@ -409,7 +413,7 @@ let reify in_macro =
 			in
 			expr "ESwitch" [loop e1;to_array scase cases p;to_opt (to_opt to_expr) def p]
 		| ETry (e1,catches) ->
-			let scatch (n,t,e) p =
+			let scatch ((n,_),t,e) p =
 				to_obj [("name",to_string n p);("type",to_ctype t p);("expr",loop e)] p
 			in
 			expr "ETry" [loop e1;to_array scatch catches p]
@@ -424,7 +428,7 @@ let reify in_macro =
 		| EThrow e ->
 			expr "EThrow" [loop e]
 		| ECast (e,ct) ->
-			expr "ECast" [loop e; to_opt to_ctype ct p]
+			expr "ECast" [loop e; to_opt to_type_hint ct p]
 		| EDisplay (e,flag) ->
 			expr "EDisplay" [loop e; to_bool flag p]
 		| EDisplayNew t ->
@@ -432,7 +436,7 @@ let reify in_macro =
 		| ETernary (e1,e2,e3) ->
 			expr "ETernary" [loop e1;loop e2;loop e3]
 		| ECheckType (e1,ct) ->
-			expr "ECheckType" [loop e1; to_ctype ct p]
+			expr "ECheckType" [loop e1; to_type_hint ct p]
 		| EMeta ((m,ml,p),e1) ->
 			match m, ml with
 			| Meta.Dollar ("" | "e"), _ ->
@@ -444,9 +448,9 @@ let reify in_macro =
 			(* TODO: can $v and $i be implemented better? *)
 			| Meta.Dollar "v", _ ->
 				begin match fst e1 with
-				| EParenthesis (ECheckType (e2, CTPath{tname="String";tpackage=[]}),_) -> expr "EConst" [mk_enum "Constant" "CString" [e2] (pos e2)]
-				| EParenthesis (ECheckType (e2, CTPath{tname="Int";tpackage=[]}),_) -> expr "EConst" [mk_enum "Constant" "CInt" [e2] (pos e2)]
-				| EParenthesis (ECheckType (e2, CTPath{tname="Float";tpackage=[]}),_) -> expr "EConst" [mk_enum "Constant" "CFloat" [e2] (pos e2)]
+				| EParenthesis (ECheckType (e2, (CTPath{tname="String";tpackage=[]},_)),_) -> expr "EConst" [mk_enum "Constant" "CString" [e2] (pos e2)]
+				| EParenthesis (ECheckType (e2, (CTPath{tname="Int";tpackage=[]},_)),_) -> expr "EConst" [mk_enum "Constant" "CInt" [e2] (pos e2)]
+				| EParenthesis (ECheckType (e2, (CTPath{tname="Float";tpackage=[]},_)),_) -> expr "EConst" [mk_enum "Constant" "CFloat" [e2] (pos e2)]
 				| _ -> (ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"Context"),p),"makeExpr"),p),[e; to_pos (pos e)]),p)
 				end
 			| Meta.Dollar "i", _ ->
@@ -475,7 +479,7 @@ let reify in_macro =
 				| HExtern | HPrivate -> ()
 				| HInterface -> interf := true;
 				| HExtends t -> ext := Some (to_tpath t p)
-				| HImplements i -> impl := (to_tpath i p) :: !impl
+				| HImplements i-> impl := (to_tpath i p) :: !impl
 			) d.d_flags;
 			to_obj [
 				"pack", (EArrayDecl [],p);
@@ -818,6 +822,9 @@ and parse_class_flags = parser
 and parse_type_hint = parser
 	| [< '(DblDot,_); t = parse_complex_type >] -> t
 
+and parse_type_hint_with_pos s = match s with parser
+	| [< '(DblDot,p1); t = parse_complex_type >] -> t
+
 and parse_type_opt = parser
 	| [< t = parse_type_hint >] -> Some t
 	| [< >] -> None
@@ -831,59 +838,59 @@ and parse_structural_extension = parser
 		t
 
 and parse_complex_type_inner = parser
-	| [< '(POpen,_); t = parse_complex_type; '(PClose,_) >] -> CTParent t
+	| [< '(POpen,p1); t = parse_complex_type; '(PClose,p2) >] -> CTParent t,punion p1 p2
 	| [< '(BrOpen,p1); s >] ->
 		(match s with parser
-		| [< l = parse_type_anonymous false >] -> CTAnonymous l
+		| [< l,p2 = parse_type_anonymous false >] -> CTAnonymous l,punion p1 p2
 		| [< t = parse_structural_extension; s>] ->
 			let tl = t :: plist parse_structural_extension s in
 			(match s with parser
-			| [< l = parse_type_anonymous false >] -> CTExtend (tl,l)
-			| [< l, _ = parse_class_fields true p1 >] -> CTExtend (tl,l))
-		| [< l, _ = parse_class_fields true p1 >] -> CTAnonymous l
+			| [< l,p2 = parse_type_anonymous false >] -> CTExtend (tl,l),punion p1 p2
+			| [< l,p2 = parse_class_fields true p1 >] -> CTExtend (tl,l),punion p1 p2)
+		| [< l,p2 = parse_class_fields true p1 >] -> CTAnonymous l,punion p1 p2
 		| [< >] -> serror())
-	| [< '(Question,_); t = parse_complex_type_inner >] ->
-		CTOptional t
-	| [< t = parse_type_path >] ->
-		CTPath t
+	| [< '(Question,p1); t,p2 = parse_complex_type_inner >] ->
+		CTOptional (t,p2),punion p1 p2
+	| [< t,p = parse_type_path >] ->
+		CTPath t,p
 
-and parse_type_path s = parse_type_path1 [] s
+and parse_type_path s = parse_type_path1 None [] s
 
-and parse_type_path1 pack = parser
-	| [< name, p = dollar_ident_macro pack; s >] ->
+and parse_type_path1 p0 pack = parser
+	| [< name, p1 = dollar_ident_macro pack; s >] ->
 		if is_lower_ident name then
 			(match s with parser
 			| [< '(Dot,p) >] ->
 				if is_resuming p then
 					raise (TypePath (List.rev (name :: pack),None,false))
 				else
-					parse_type_path1 (name :: pack) s
+					parse_type_path1 (match p0 with None -> Some p1 | Some _ -> p0) (name :: pack) s
 			| [< '(Semicolon,_) >] ->
-				error (Custom "Type name should start with an uppercase letter") p
+				error (Custom "Type name should start with an uppercase letter") p1
 			| [< >] -> serror())
 		else
-			let sub = (match s with parser
+			let sub,p2 = (match s with parser
 				| [< '(Dot,p); s >] ->
 					(if is_resuming p then
 						raise (TypePath (List.rev pack,Some (name,false),false))
 					else match s with parser
-						| [< '(Const (Ident name),_) when not (is_lower_ident name) >] -> Some name
+						| [< '(Const (Ident name),p2) when not (is_lower_ident name) >] -> Some name,p2
 						| [< '(Binop OpOr,_) when do_resume() >] ->
 							set_resume p;
 							raise (TypePath (List.rev pack,Some (name,false),false))
 						| [< >] -> serror())
-				| [< >] -> None
+				| [< >] -> None,p1
 			) in
-			let params = (match s with parser
-				| [< '(Binop OpLt,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt,_) >] -> l
-				| [< >] -> []
+			let params,p2 = (match s with parser
+				| [< '(Binop OpLt,_); l = psep Comma parse_type_path_or_const; '(Binop OpGt,p2) >] -> l,p2
+				| [< >] -> [],p2
 			) in
 			{
 				tpackage = List.rev pack;
 				tname = name;
 				tparams = params;
 				tsub = sub;
-			}
+			},punion (match p0 with None -> p1 | Some p -> p) p2
 	| [< '(Binop OpOr,_) when do_resume() >] ->
 		raise (TypePath (List.rev pack,None,false))
 
@@ -903,18 +910,18 @@ and parse_type_path_or_const = parser
 	| [< e = expr >] -> TPExpr e
 	| [< >] -> serror()
 
-and parse_complex_type_next t = parser
-	| [< '(Arrow,_); t2 = parse_complex_type >] ->
+and parse_complex_type_next (t : type_hint) = parser
+	| [< '(Arrow,_); t2,p2 = parse_complex_type >] ->
 		(match t2 with
 		| CTFunction (args,r) ->
-			CTFunction (t :: args,r)
+			CTFunction (t :: args,r),punion (pos t) p2
 		| _ ->
-			CTFunction ([t] , t2))
+			CTFunction ([t] , (t2,p2)),punion (pos t) p2)
 	| [< >] -> t
 
 and parse_type_anonymous opt = parser
 	| [< '(Question,_) when not opt; s >] -> parse_type_anonymous true s
-	| [< name, p1 = ident; t = parse_type_hint; s >] ->
+	| [< name, p1 = ident; t = parse_type_hint_with_pos; s >] ->
 		let next p2 acc =
 			{
 				cff_name = name;
@@ -926,11 +933,11 @@ and parse_type_anonymous opt = parser
 			} :: acc
 		in
 		match s with parser
-		| [< '(BrClose,p2) >] -> next p2 []
+		| [< '(BrClose,p2) >] -> next p2 [],p2
 		| [< '(Comma,p2) >] ->
 			(match s with parser
-			| [< '(BrClose,_) >] -> next p2 []
-			| [< l = parse_type_anonymous false >] -> next p2 l
+			| [< '(BrClose,p2) >] -> next p2 [],p2
+			| [< l,p2 = parse_type_anonymous false >] -> next p2 l,punion p1 p2
 			| [< >] -> serror());
 		| [< >] -> serror()
 
@@ -943,7 +950,7 @@ and parse_enum s =
 		| [< '(POpen,_); l = psep Comma parse_enum_param; '(PClose,_) >] -> l
 		| [< >] -> []
 		) in
-		let t = parse_type_opt s in
+		let t = popt parse_type_hint_with_pos s in
 		let p2 = (match s with parser
 			| [< p = semicolon >] -> p
 			| [< >] -> serror()
@@ -959,8 +966,8 @@ and parse_enum s =
 		}
 
 and parse_enum_param = parser
-	| [< '(Question,_); name, _ = ident; t = parse_type_hint >] -> (name,true,t)
-	| [< name, _ = ident; t = parse_type_hint >] -> (name,false,t)
+	| [< '(Question,_); name, _ = ident; t = parse_type_hint_with_pos >] -> (name,true,t)
+	| [< name, _ = ident; t = parse_type_hint_with_pos >] -> (name,false,t)
 
 and parse_class_field s =
 	let doc = get_doc s in
@@ -970,21 +977,21 @@ and parse_class_field s =
 		| [< '(Kwd Var,p1); name, _ = dollar_ident; s >] ->
 			(match s with parser
 			| [< '(POpen,_); i1 = property_ident; '(Comma,_); i2 = property_ident; '(PClose,_) >] ->
-				let t = parse_type_opt s in
+				let t = popt parse_type_hint_with_pos s in
 				let e , p2 = (match s with parser
 				| [< '(Binop OpAssign,_); e = toplevel_expr; p2 = semicolon >] -> Some e , p2
 				| [< '(Semicolon,p2) >] -> None , p2
 				| [< >] -> serror()
 				) in
 				name, punion p1 p2, FProp (i1,i2,t, e)
-			| [< t = parse_type_opt; s >] ->
+			| [< t = popt parse_type_hint_with_pos; s >] ->
 				let e , p2 = (match s with parser
 				| [< '(Binop OpAssign,_); e = toplevel_expr; p2 = semicolon >] -> Some e , p2
 				| [< '(Semicolon,p2) >] -> None , p2
 				| [< >] -> serror()
 				) in
 				name, punion p1 p2, FVar (t,e))
-		| [< '(Kwd Function,p1); name = parse_fun_name; pl = parse_constraint_params; '(POpen,_); al = psep Comma parse_fun_param; '(PClose,_); t = parse_type_opt; s >] ->
+		| [< '(Kwd Function,p1); name = parse_fun_name; pl = parse_constraint_params; '(POpen,_); al = psep Comma parse_fun_param; '(PClose,_); t = popt parse_type_hint_with_pos; s >] ->
 			let e, p2 = (match s with parser
 				| [< e = toplevel_expr; s >] ->
 					(try ignore(semicolon s) with Error (Missing_semicolon,p) -> !display_error Missing_semicolon p);
@@ -1025,9 +1032,11 @@ and parse_fun_name = parser
 	| [< name,_ = dollar_ident >] -> name
 	| [< '(Kwd New,_) >] -> "new"
 
-and parse_fun_param = parser
-	| [< '(Question,_); name, _ = dollar_ident; t = parse_type_opt; c = parse_fun_param_value >] -> (name,true,t,c)
-	| [< name, _ = dollar_ident; t = parse_type_opt; c = parse_fun_param_value >] -> (name,false,t,c)
+and parse_fun_param s =
+	let meta = parse_meta s in
+	match s with parser
+	| [< '(Question,_); name, pn = dollar_ident; t = popt parse_type_hint_with_pos; c = parse_fun_param_value >] -> ((name,pn),true,meta,t,c)
+	| [< name, pn = dollar_ident; t = popt parse_type_hint_with_pos; c = parse_fun_param_value >] -> ((name,pn),false,meta,t,c)
 
 and parse_fun_param_value = parser
 	| [< '(Binop OpAssign,_); e = toplevel_expr >] -> Some e
@@ -1123,7 +1132,7 @@ and parse_array_decl = parser
 		[]
 
 and parse_var_decl_head = parser
-	| [< name, _ = dollar_ident; t = parse_type_opt >] -> (name,t)
+	| [< name, p = dollar_ident; t = popt parse_type_hint_with_pos >] -> (name,t,p)
 
 and parse_var_assignment = parser
 	| [< '(Binop OpAssign,p1); s >] ->
@@ -1134,12 +1143,12 @@ and parse_var_assignment = parser
 	| [< >] -> None
 
 and parse_var_decls_next vl = parser
-	| [< '(Comma,p1); name,t = parse_var_decl_head; s >] ->
+	| [< '(Comma,p1); name,t,pn = parse_var_decl_head; s >] ->
 		begin try
 			let eo = parse_var_assignment s in
-			parse_var_decls_next ((name,t,eo) :: vl) s
+			parse_var_decls_next (((name,pn),t,eo) :: vl) s
 		with Display e ->
-			let v = (name,t,Some e) in
+			let v = ((name,pn),t,Some e) in
 			let e = (EVars(List.rev (v :: vl)),punion p1 (pos e)) in
 			display e
 		end
@@ -1147,13 +1156,13 @@ and parse_var_decls_next vl = parser
 		vl
 
 and parse_var_decls p1 = parser
-	| [< name,t = parse_var_decl_head; s >] ->
+	| [< name,t,pn = parse_var_decl_head; s >] ->
 		let eo = parse_var_assignment s in
-		List.rev (parse_var_decls_next [name,t,eo] s)
+		List.rev (parse_var_decls_next [(name,pn),t,eo] s)
 	| [< s >] -> error (Custom "Missing variable identifier") p1
 
 and parse_var_decl = parser
-	| [< name,t = parse_var_decl_head; eo = parse_var_assignment >] -> (name,t,eo)
+	| [< name,t,pn = parse_var_decl_head; eo = parse_var_assignment >] -> ((name,pn),t,eo)
 
 and inline_function = parser
 	| [< '(Kwd Inline,_); '(Kwd Function,p1) >] -> true, p1
@@ -1162,23 +1171,23 @@ and inline_function = parser
 and reify_expr e =
 	let to_expr,_,_ = reify !in_macro in
 	let e = to_expr e in
-	(ECheckType (e,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = None; tparams = [] })),pos e)
+	(ECheckType (e,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = None; tparams = [] },null_pos)),pos e)
 
 and parse_macro_expr p = parser
 	| [< '(DblDot,_); t = parse_complex_type >] ->
 		let _, to_type, _  = reify !in_macro in
 		let t = to_type t p in
-		(ECheckType (t,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some "ComplexType"; tparams = [] })),p)
+		(ECheckType (t,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some "ComplexType"; tparams = [] },null_pos)),p)
 	| [< '(Kwd Var,p1); vl = psep Comma parse_var_decl >] ->
 		reify_expr (EVars vl,p1)
 	| [< d = parse_class None [] [] false >] ->
 		let _,_,to_type = reify !in_macro in
-		(ECheckType (to_type d,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some "TypeDefinition"; tparams = [] })),p)
+		(ECheckType (to_type d,(CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some "TypeDefinition"; tparams = [] },null_pos)),p)
 	| [< e = secure_expr >] ->
 		reify_expr e
 
 and parse_function p1 inl = parser
-	| [< name = popt dollar_ident; pl = parse_constraint_params; '(POpen,_); al = psep Comma parse_fun_param; '(PClose,_); t = parse_type_opt; s >] ->
+	| [< name = popt dollar_ident; pl = parse_constraint_params; '(POpen,_); al = psep Comma parse_fun_param; '(PClose,_); t = popt parse_type_hint_with_pos; s >] ->
 		let make e =
 			let f = {
 				f_params = pl;
@@ -1222,9 +1231,9 @@ and expr = parser
 		(match s with parser
 		| [< '(POpen,pp); e = expr; s >] ->
 			(match s with parser
-			| [< '(Comma,_); t = parse_complex_type; '(PClose,p2); s >] -> expr_next (ECast (e,Some t),punion p1 p2) s
-			| [< t = parse_type_hint; '(PClose,p2); s >] ->
-				let ep = EParenthesis (ECheckType(e,t),punion p1 p2), punion p1 p2 in
+			| [< '(Comma,pc); t = parse_complex_type; '(PClose,p2); s >] -> expr_next (ECast (e,Some t),punion p1 p2) s
+			| [< t,pt = parse_type_hint_with_pos; '(PClose,p2); s >] ->
+				let ep = EParenthesis (ECheckType(e,(t,pt)),punion p1 p2), punion p1 p2 in
 				expr_next (ECast (ep,None),punion p1 (pos ep)) s
 			| [< '(Const (Ident "is"),_); t = parse_type_path; '(PClose,p2); >] ->
 				let e_is = make_is e t (punion p1 p2) in
@@ -1242,7 +1251,7 @@ and expr = parser
 		| [< >] -> serror())
 	| [< '(POpen,p1); e = expr; s >] -> (match s with parser
 		| [< '(PClose,p2); s >] -> expr_next (EParenthesis e, punion p1 p2) s
-		| [< t = parse_type_hint; '(PClose,p2); s >] -> expr_next (EParenthesis (ECheckType(e,t),punion p1 p2), punion p1 p2) s
+		| [< t,pt = parse_type_hint_with_pos; '(PClose,p2); s >] -> expr_next (EParenthesis (ECheckType(e,(t,pt)),punion p1 p2), punion p1 p2) s
 		| [< '(Const (Ident "is"),_); t = parse_type_path; '(PClose,p2); >] -> expr_next (make_is e t (punion p1 p2)) s
 		| [< >] -> serror())
 	| [< '(BkOpen,p1); l = parse_array_decl; '(BkClose,p2); s >] -> expr_next (EArrayDecl l, punion p1 p2) s
@@ -1387,13 +1396,13 @@ and parse_switch_cases eswitch cases = parser
 		List.rev cases , None
 
 and parse_catch etry = parser
-	| [< '(Kwd Catch,p); '(POpen,_); name, _ = dollar_ident; s >] ->
+	| [< '(Kwd Catch,p); '(POpen,_); name, pn = dollar_ident; s >] ->
 		match s with parser
-		| [< t = parse_type_hint; '(PClose,_); s >] ->
+		| [< t,pt = parse_type_hint_with_pos; '(PClose,_); s >] ->
 			(try
-				(name,t,secure_expr s)
+				((name,pn),(t,pt),secure_expr s)
 			with
-				Display e -> display (ETry (etry,[name,t,e]),punion (pos etry) (pos e)))
+				Display e -> display (ETry (etry,[(name,pn),(t,pt),e]),punion (pos etry) (pos e)))
 		| [< '(_,p) >] -> error Missing_type p
 
 and parse_call_params ec s =

+ 4 - 4
src/typing/matcher.ml

@@ -54,7 +54,7 @@ let get_general_module_type ctx mt p =
 			end
 		| _ -> error "Cannot use this type as a value" p
 	in
-	Typeload.load_instance ctx {tname=loop mt;tpackage=[];tsub=None;tparams=[]} p true
+	Typeload.load_instance ctx ({tname=loop mt;tpackage=[];tsub=None;tparams=[]},p) true
 
 module Constructor = struct
 	type t =
@@ -252,7 +252,7 @@ module Pattern = struct
 		let rec loop e = match fst e with
 			| EParenthesis e1 | ECast(e1,None) ->
 				loop e1
-			| ECheckType(e, CTPath({tpackage=["haxe";"macro"]; tname="Expr"})) ->
+			| ECheckType(e, (CTPath({tpackage=["haxe";"macro"]; tname="Expr"}),_)) ->
 				let old = pctx.in_reification in
 				pctx.in_reification <- true;
 				let e = loop e in
@@ -275,7 +275,7 @@ module Pattern = struct
 					| _ ->
 						handle_ident i
 				end
-			| EVars([s,None,None]) ->
+			| EVars([(s,_),None,None]) ->
 				let v = add_local s in
 				PatVariable v
 			| ECall(e1,el) ->
@@ -1224,7 +1224,7 @@ module TexprConverter = struct
 	let to_texpr ctx t_switch match_debug with_type dt =
 		let com = ctx.com in
 		let p = dt.dt_pos in
-		let c_type = match follow (Typeload.load_instance ctx { tpackage = ["std"]; tname="Type"; tparams=[]; tsub = None} p true) with TInst(c,_) -> c | t -> assert false in
+		let c_type = match follow (Typeload.load_instance ctx ({ tpackage = ["std"]; tname="Type"; tparams=[]; tsub = None},p) true) with TInst(c,_) -> c | t -> assert false in
 		let mk_index_call e =
 			let cf = PMap.find "enumIndex" c_type.cl_statics in
 			make_static_call ctx c_type cf (fun t -> t) [e] com.basic.tint e.epos

+ 22 - 19
src/typing/type.ml

@@ -2369,31 +2369,31 @@ module TExprToExpr = struct
 			CTPath {
 				tpackage = [];
 				tname = name;
-				tparams = List.map (fun t -> TPType (convert_type t)) tl;
+				tparams = List.map (fun t -> TPType (convert_type' t)) tl;
 				tsub = None;
 			}
 		| TEnum (e,pl) ->
-			tpath e.e_path e.e_module.m_path (List.map convert_type pl)
+			tpath e.e_path e.e_module.m_path (List.map convert_type' pl)
 		| TInst({cl_kind = KTypeParameter _} as c,pl) ->
-			tpath ([],snd c.cl_path) ([],snd c.cl_path) (List.map convert_type pl)
+			tpath ([],snd c.cl_path) ([],snd c.cl_path) (List.map convert_type' pl)
 		| TInst (c,pl) ->
-			tpath c.cl_path c.cl_module.m_path (List.map convert_type pl)
+			tpath c.cl_path c.cl_module.m_path (List.map convert_type' pl)
 		| TType (t,pl) as tf ->
 			(* recurse on type-type *)
-			if (snd t.t_path).[0] = '#' then convert_type (follow tf) else tpath t.t_path t.t_module.m_path (List.map convert_type pl)
+			if (snd t.t_path).[0] = '#' then convert_type (follow tf) else tpath t.t_path t.t_module.m_path (List.map convert_type' pl)
 		| TAbstract (a,pl) ->
-			tpath a.a_path a.a_module.m_path (List.map convert_type pl)
+			tpath a.a_path a.a_module.m_path (List.map convert_type' pl)
 		| TFun (args,ret) ->
-			CTFunction (List.map (fun (_,_,t) -> convert_type t) args, convert_type ret)
+			CTFunction (List.map (fun (_,_,t) -> convert_type' t) args, (convert_type' ret))
 		| TAnon a ->
 			begin match !(a.a_status) with
-			| Statics c -> tpath ([],"Class") ([],"Class") [tpath c.cl_path c.cl_path []]
-			| EnumStatics e -> tpath ([],"Enum") ([],"Enum") [tpath e.e_path e.e_path []]
+			| Statics c -> tpath ([],"Class") ([],"Class") [tpath c.cl_path c.cl_path [],null_pos]
+			| EnumStatics e -> tpath ([],"Enum") ([],"Enum") [tpath e.e_path e.e_path [],null_pos]
 			| _ ->
 				CTAnonymous (PMap.foldi (fun _ f acc ->
 					{
 						cff_name = f.cf_name;
-						cff_kind = FVar (mk_ot f.cf_type,None);
+						cff_kind = FVar (mk_type_hint f.cf_type null_pos,None);
 						cff_pos = f.cf_pos;
 						cff_doc = f.cf_doc;
 						cff_meta = f.cf_meta;
@@ -2402,14 +2402,17 @@ module TExprToExpr = struct
 				) a.a_fields [])
 			end
 		| (TDynamic t2) as t ->
-			tpath ([],"Dynamic") ([],"Dynamic") (if t == t_dynamic then [] else [convert_type t2])
+			tpath ([],"Dynamic") ([],"Dynamic") (if t == t_dynamic then [] else [convert_type' t2])
 		| TLazy f ->
 			convert_type ((!f)())
 
-	and mk_ot t =
+	and convert_type' t =
+		convert_type t,null_pos
+
+	and mk_type_hint t p =
 		match follow t with
 		| TMono _ -> None
-		| _ -> (try Some (convert_type t) with Exit -> None)
+		| _ -> (try Some (convert_type t,p) with Exit -> None)
 
 	let rec convert_expr e =
 		let full_type_path t =
@@ -2439,13 +2442,13 @@ module TExprToExpr = struct
 		| TObjectDecl fl -> EObjectDecl (List.map (fun (f,e) -> f, convert_expr e) fl)
 		| TArrayDecl el -> EArrayDecl (List.map convert_expr el)
 		| TCall (e,el) -> ECall (convert_expr e,List.map convert_expr el)
-		| TNew (c,pl,el) -> ENew ((match (try convert_type (TInst (c,pl)) with Exit -> convert_type (TInst (c,[]))) with CTPath p -> p | _ -> assert false),List.map convert_expr el)
+		| TNew (c,pl,el) -> ENew ((match (try convert_type (TInst (c,pl)) with Exit -> convert_type (TInst (c,[]))) with CTPath p -> p,null_pos | _ -> assert false),List.map convert_expr el)
 		| TUnop (op,p,e) -> EUnop (op,p,convert_expr e)
 		| TFunction f ->
-			let arg (v,c) = v.v_name, false, mk_ot v.v_type, (match c with None -> None | Some c -> Some (EConst (tconst_to_const c),e.epos)) in
-			EFunction (None,{ f_params = []; f_args = List.map arg f.tf_args; f_type = mk_ot f.tf_type; f_expr = Some (convert_expr f.tf_expr) })
+			let arg (v,c) = (v.v_name,v.v_pos), false, v.v_meta, mk_type_hint v.v_type null_pos, (match c with None -> None | Some c -> Some (EConst (tconst_to_const c),e.epos)) in
+			EFunction (None,{ f_params = []; f_args = List.map arg f.tf_args; f_type = mk_type_hint f.tf_type null_pos; f_expr = Some (convert_expr f.tf_expr) })
 		| TVar (v,eo) ->
-			EVars ([v.v_name, mk_ot v.v_type, eopt eo])
+			EVars ([(v.v_name,v.v_pos), mk_type_hint v.v_type v.v_pos, eopt eo])
 		| TBlock el -> EBlock (List.map convert_expr el)
 		| TFor (v,it,e) ->
 			let ein = (EIn ((EConst (Ident v.v_name),it.epos),convert_expr it),it.epos) in
@@ -2461,7 +2464,7 @@ module TExprToExpr = struct
 		| TEnumParameter _ ->
 			(* these are considered complex, so the AST is handled in TMeta(Meta.Ast) *)
 			assert false
-		| TTry (e,catches) -> ETry (convert_expr e,List.map (fun (v,e) -> v.v_name, (try convert_type v.v_type with Exit -> assert false), convert_expr e) catches)
+		| TTry (e,catches) -> ETry (convert_expr e,List.map (fun (v,e) -> (v.v_name,v.v_pos), (try convert_type v.v_type,null_pos with Exit -> assert false), convert_expr e) catches)
 		| TReturn e -> EReturn (eopt e)
 		| TBreak -> EBreak
 		| TContinue -> EContinue
@@ -2471,7 +2474,7 @@ module TExprToExpr = struct
 				| None -> None
 				| Some t ->
 					let t = (match t with TClassDecl c -> TInst (c,[]) | TEnumDecl e -> TEnum (e,[]) | TTypeDecl t -> TType (t,[]) | TAbstractDecl a -> TAbstract (a,[])) in
-					Some (try convert_type t with Exit -> assert false)
+					Some (try convert_type t,null_pos with Exit -> assert false)
 			) in
 			ECast (convert_expr e,t)
 		| TMeta ((Meta.Ast,[e1,_],_),_) -> e1

+ 1 - 1
src/typing/typecore.ml

@@ -78,7 +78,7 @@ type typer_globals = {
 	delayed_macros : (unit -> unit) DynArray.t;
 	mutable global_using : tclass list;
 	(* api *)
-	do_inherit : typer -> Type.tclass -> Ast.pos -> (bool * Ast.type_path) -> bool;
+	do_inherit : typer -> Type.tclass -> Ast.pos -> (bool * Ast.placed_type_path) -> bool;
 	do_create : Common.context -> typer;
 	do_macro : typer -> macro_mode -> path -> string -> Ast.expr list -> Ast.pos -> Ast.expr option;
 	do_load_module : typer -> path -> pos -> module_def;

+ 100 - 91
src/typing/typeload.ml

@@ -37,7 +37,7 @@ let transform_abstract_field com this_t a_t a f =
 	| FProp _ when not stat ->
 		error "Member property accessors must be get/set or never" p;
 	| FFun fu when f.cff_name = "new" && not stat ->
-		let init p = (EVars ["this",Some this_t,None],p) in
+		let init p = (EVars [("this",null_pos),Some this_t,None],p) in
 		let cast e = (ECast(e,None)),pos e in
 		let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
 		let meta = (Meta.Impl,[],p) :: f.cff_meta in
@@ -61,7 +61,7 @@ let transform_abstract_field com this_t a_t a f =
 		{ f with cff_name = "_new"; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = meta }
 	| FFun fu when not stat ->
 		if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
-		let fu = { fu with f_args = (if List.mem AMacro f.cff_access then fu.f_args else ("this",false,Some this_t,None) :: fu.f_args) } in
+		let fu = { fu with f_args = (if List.mem AMacro f.cff_access then fu.f_args else (("this",null_pos),false,[],Some this_t,None) :: fu.f_args) } in
 		{ f with cff_kind = FFun fu; cff_access = AStatic :: f.cff_access; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 	| _ ->
 		f
@@ -189,8 +189,8 @@ let module_pass_1 ctx m tdecls loadp =
 				acc
 			| fields ->
 				let a_t =
-					let params = List.map (fun t -> TPType (CTPath { tname = t.tp_name; tparams = []; tsub = None; tpackage = [] })) d.d_params in
-					CTPath { tpackage = []; tname = d.d_name; tparams = params; tsub = None }
+					let params = List.map (fun t -> TPType (CTPath { tname = t.tp_name; tparams = []; tsub = None; tpackage = [] },null_pos)) d.d_params in
+					CTPath { tpackage = []; tname = d.d_name; tparams = params; tsub = None },null_pos
 				in
 				let rec loop = function
 					| [] -> a_t
@@ -368,15 +368,15 @@ let requires_value_meta com co =
 
 let generate_value_meta com co cf args =
 	if requires_value_meta com co then begin
-		let values = List.fold_left (fun acc (name,_,_,eo) -> match eo with Some e -> (name,e) :: acc | _ -> acc) [] args in
+		let values = List.fold_left (fun acc ((name,_),_,_,_,eo) -> match eo with Some e -> (name,e) :: acc | _ -> acc) [] args in
 		match values with
 			| [] -> ()
 			| _ -> cf.cf_meta <- ((Meta.Value,[EObjectDecl values,cf.cf_pos],cf.cf_pos) :: cf.cf_meta)
 	end
 
 (* build an instance from a full type *)
-let rec load_instance ctx t p allow_no_params =
-	try
+let rec load_instance ?(allow_display=false) ctx (t,p) allow_no_params =
+	let t = try
 		if t.tpackage <> [] || t.tsub <> None then raise Not_found;
 		let pt = List.assoc t.tname ctx.type_params in
 		if t.tparams <> [] then error ("Class type parameter " ^ t.tname ^ " can't have parameters") p;
@@ -404,7 +404,7 @@ let rec load_instance ctx t p allow_no_params =
 		end else if path = ([],"Dynamic") then
 			match t.tparams with
 			| [] -> t_dynamic
-			| [TPType t] -> TDynamic (load_complex_type ctx p t)
+			| [TPType t] -> TDynamic (load_complex_type ctx false t)
 			| _ -> error "Too many parameters for Dynamic" p
 		else begin
 			if not is_rest && List.length types <> List.length t.tparams then error ("Invalid number of type parameters for " ^ s_type_path path) p;
@@ -420,7 +420,7 @@ let rec load_instance ctx t p allow_no_params =
 					let c = mk_class null_module ([],name) p in
 					c.cl_kind <- KExpr e;
 					TInst (c,[])
-				| TPType t -> load_complex_type ctx p t
+				| TPType t -> load_complex_type ctx true t
 			) t.tparams in
 			let rec loop tl1 tl2 is_rest = match tl1,tl2 with
 				| t :: tl1,(name,t2) :: tl2 ->
@@ -466,16 +466,21 @@ let rec load_instance ctx t p allow_no_params =
 			let params = loop tparams types false in
 			f params
 		end
+	in
+	if allow_display && ctx.com.display <> DMNone && Display.is_display_file p && Display.encloses_position !Parser.resume_display p then
+		Display.display_type ctx.com.display t;
+	t
+
 (*
 	build an instance from a complex type
 *)
-and load_complex_type ctx p t =
+and load_complex_type ctx allow_display (t,p) =
 	match t with
-	| CTParent t -> load_complex_type ctx p t
-	| CTPath t -> load_instance ctx t p false
+	| CTParent t -> load_complex_type ctx allow_display t
+	| CTPath t -> load_instance ~allow_display ctx (t,p) false
 	| CTOptional _ -> error "Optional type not allowed here" p
 	| CTExtend (tl,l) ->
-		(match load_complex_type ctx p (CTAnonymous l) with
+		(match load_complex_type ctx allow_display (CTAnonymous l,p) with
 		| TAnon a as ta ->
 			let is_redefined cf1 a2 =
 				try
@@ -526,7 +531,7 @@ and load_complex_type ctx p t =
 				| _ ->
 					error "Multiple structural extension is only allowed for structures" p
 			in
-			let il = List.map (fun t -> load_instance ctx t p false) tl in
+			let il = List.map (fun (t,_) -> load_instance ctx ~allow_display (t,p) false) tl in
 			let tr = ref None in
 			let t = TMono tr in
 			let r = exc_protect ctx (fun r ->
@@ -550,7 +555,7 @@ and load_complex_type ctx p t =
 			if PMap.mem n acc then error ("Duplicate field declaration : " ^ n) p;
 			let topt = function
 				| None -> error ("Explicit type required for field " ^ n) p
-				| Some t -> load_complex_type ctx p t
+				| Some t -> load_complex_type ctx allow_display t
 			in
 			if n = "new" then ctx.com.warning "Structures with new are deprecated, use haxe.Constraints.Constructible instead" p;
 			let no_expr = function
@@ -568,7 +573,7 @@ and load_complex_type ctx p t =
 				| AStatic | AOverride | AInline | ADynamic | AMacro -> error ("Invalid access " ^ Ast.s_access a) p
 			) f.cff_access;
 			let t , access = (match f.cff_kind with
-				| FVar (Some (CTPath({tpackage=[];tname="Void"})), _)  | FProp (_,_,Some (CTPath({tpackage=[];tname="Void"})),_) ->
+				| FVar (Some (CTPath({tpackage=[];tname="Void"}),_), _)  | FProp (_,_,Some (CTPath({tpackage=[];tname="Void"}),_),_) ->
 					error "Fields of type Void are not allowed in structures" p
 				| FVar (t, e) ->
 					no_expr e;
@@ -578,7 +583,7 @@ and load_complex_type ctx p t =
 					no_expr fd.f_expr;
 					let old = ctx.type_params in
 					ctx.type_params <- !params @ old;
-					let args = List.map (fun (name,o,t,e) -> no_expr e; name, o, topt t) fd.f_args in
+					let args = List.map (fun ((name,_),o,_,t,e) -> no_expr e; name, o, topt t) fd.f_args in
 					let t = TFun (args,topt fd.f_type), Method (if !dyn then MethDynamic else MethNormal) in
 					ctx.type_params <- old;
 					t
@@ -598,7 +603,7 @@ and load_complex_type ctx p t =
 							error "Custom property access is no longer supported in Haxe 3" f.cff_pos;
 					in
 					let t = (match t with None -> error "Type required for structure property" p | Some t -> t) in
-					load_complex_type ctx p t, Var { v_read = access i1 true; v_write = access i2 false }
+					load_complex_type ctx allow_display t, Var { v_read = access i1 true; v_write = access i2 false }
 			) in
 			let t = if Meta.has Meta.Optional f.cff_meta then ctx.t.tnull t else t in
 			let cf = {
@@ -619,13 +624,13 @@ and load_complex_type ctx p t =
 		mk_anon (List.fold_left loop PMap.empty l)
 	| CTFunction (args,r) ->
 		match args with
-		| [CTPath { tpackage = []; tparams = []; tname = "Void" }] ->
-			TFun ([],load_complex_type ctx p r)
+		| [CTPath { tpackage = []; tparams = []; tname = "Void" },_] ->
+			TFun ([],load_complex_type ctx allow_display r)
 		| _ ->
 			TFun (List.map (fun t ->
-				let t, opt = (match t with CTOptional t -> t, true | _ -> t,false) in
-				"",opt,load_complex_type ctx p t
-			) args,load_complex_type ctx p r)
+				let t, opt = (match fst t with CTOptional t -> t, true | _ -> t,false) in
+				"",opt,load_complex_type ctx allow_display t
+			) args,load_complex_type ctx allow_display r)
 
 and init_meta_overloads ctx co cf =
 	let overloads = ref [] in
@@ -645,8 +650,8 @@ and init_meta_overloads ctx co cf =
 			| l -> ctx.type_params <- List.filter (fun t -> not (List.mem t l)) ctx.type_params);
 			let params = (!type_function_params_rec) ctx f cf.cf_name p in
 			ctx.type_params <- params @ ctx.type_params;
-			let topt = function None -> error "Explicit type required" p | Some t -> load_complex_type ctx p t in
-			let args = List.map (fun (a,opt,t,_) ->  a,opt,topt t) f.f_args in
+			let topt = function None -> error "Explicit type required" p | Some t -> load_complex_type ctx true t in
+			let args = List.map (fun ((a,_),opt,_,t,_) -> a,opt,topt t) f.f_args in
 			let cf = { cf with cf_type = TFun (args,topt f.f_type); cf_params = params; cf_meta = cf_meta} in
 			generate_value_meta ctx.com co cf f.f_args;
 			overloads := cf :: !overloads;
@@ -692,7 +697,7 @@ let hide_params ctx =
 *)
 let load_core_type ctx name =
 	let show = hide_params ctx in
-	let t = load_instance ctx { tpackage = []; tname = name; tparams = []; tsub = None; } null_pos false in
+	let t = load_instance ctx ({ tpackage = []; tname = name; tparams = []; tsub = None; },null_pos) false in
 	show();
 	add_dependency ctx.m.curmod (match t with
 	| TInst (c,_) -> c.cl_module
@@ -717,8 +722,11 @@ let t_iterator ctx =
 (*
 	load either a type t or Null<Unknown> if not defined
 *)
-let load_type_opt ?(opt=false) ctx p t =
-	let t = (match t with None -> mk_mono() | Some t -> load_complex_type ctx p t) in
+let load_type_hint ?(opt=false) ctx t =
+	let t = match t with
+		| None -> mk_mono()
+		| Some (t,p) -> load_complex_type ctx true (t,p)
+	in
 	if opt then ctx.t.tnull t else t
 
 (* ---------------------------------------------------------------------- *)
@@ -1165,19 +1173,19 @@ let get_strict_meta ctx params pos =
 			in
 			let tpath = field_to_type_path ctx ef in
 			if pf = Cs then
-				(ENew(tpath, el), p), fields, CTPath tpath
+				(ENew((tpath,snd ef), el), p), fields, CTPath tpath
 			else
 				ef, fields, CTPath tpath
 		| [EConst(Ident i),p as expr] ->
 			let tpath = { tpackage=[]; tname=i; tparams=[]; tsub=None } in
 			if pf = Cs then
-				(ENew(tpath, []), p), [], CTPath tpath
+				(ENew((tpath,p), []), p), [], CTPath tpath
 			else
 				expr, [], CTPath tpath
 		| [ (EField(_),p as field) ] ->
 			let tpath = field_to_type_path ctx field in
 			if pf = Cs then
-				(ENew(tpath, []), p), [], CTPath tpath
+				(ENew((tpath,p), []), p), [], CTPath tpath
 			else
 				field, [], CTPath tpath
 		| _ ->
@@ -1185,7 +1193,7 @@ let get_strict_meta ctx params pos =
 			raise Exit
 	in
 	let texpr = type_expr ctx changed_expr NoValue in
-	let with_type_expr = (ECheckType( (EConst (Ident "null"), pos), ctype ), pos) in
+	let with_type_expr = (ECheckType( (EConst (Ident "null"), pos), (ctype,null_pos) ), pos) in
 	let extra = handle_fields ctx fields_to_check with_type_expr in
 	Meta.Meta, [make_meta ctx texpr extra], pos
 
@@ -1418,16 +1426,16 @@ module Inheritance = struct
 			resolve imports before calling build_inheritance, since it requires full paths.
 			that means that typedefs are not working, but that's a fair limitation
 		*)
-		let resolve_imports t =
+		let resolve_imports (t,p) =
 			match t.tpackage with
-			| _ :: _ -> t
+			| _ :: _ -> t,p
 			| [] ->
 				try
 					let find = List.find (fun lt -> snd (t_path lt) = t.tname) in
 					let lt = try find ctx.m.curmod.m_types with Not_found -> find ctx.m.module_types in
-					{ t with tpackage = fst (t_path lt) }
+					{ t with tpackage = fst (t_path lt) },p
 				with
-					Not_found -> t
+					Not_found -> t,p
 		in
 		let herits = ExtList.List.filter_map (function
 			| HExtends t -> Some(true,resolve_imports t)
@@ -1437,7 +1445,7 @@ module Inheritance = struct
 		let herits = List.filter (ctx.g.do_inherit ctx c p) herits in
 		(* Pass 1: Check and set relations *)
 		let fl = List.map (fun (is_extends,t) ->
-			let t = load_instance ctx t p false in
+			let t = load_instance ~allow_display:true ctx t false in
 			if is_extends then begin
 				if c.cl_super <> None then error "Cannot extend several classes" p;
 				let csup,params = check_extends ctx c t p in
@@ -1500,7 +1508,7 @@ let rec type_type_param ?(enum_constructor=false) ctx path get_params p tp =
 		let r = exc_protect ctx (fun r ->
 			r := (fun _ -> t);
 			let ctx = { ctx with type_params = ctx.type_params @ get_params() } in
-			let constr = List.map (load_complex_type ctx p) tp.tp_constraints in
+			let constr = List.map (load_complex_type ctx true) tp.tp_constraints in
 			(* check against direct recursion *)
 			let rec loop t =
 				match follow t with
@@ -1532,13 +1540,14 @@ let type_function_params ctx fd fname p =
 
 let type_function ctx args ret fmode f do_display p =
 	let locals = save_locals ctx in
-	let fargs = List.map (fun (n,c,t) ->
+	let fargs = List.map2 (fun (n,c,t) ((_,pn),_,m,_,_) ->
 		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 p, c in (* TODO: var pos *)
+		let v,c = add_local ctx n t pn, c in
+		v.v_meta <- m;
 		if n = "this" then v.v_meta <- (Meta.This,[],p) :: v.v_meta;
 		v,c
-	) args in
+	) args f.f_args in
 	let old_ret = ctx.ret in
 	let old_fun = ctx.curfun in
 	let old_opened = ctx.opened in
@@ -1656,7 +1665,7 @@ let load_core_class ctx c =
 		| KAbstractImpl a -> { tpackage = fst a.a_path; tname = snd a.a_path; tparams = []; tsub = None; }
 		| _ -> { tpackage = fst c.cl_path; tname = snd c.cl_path; tparams = []; tsub = None; }
 	in
-	let t = load_instance ctx2 tpath c.cl_pos true in
+	let t = load_instance ctx2 (tpath,c.cl_pos) true in
 	flush_pass ctx2 PFinal "core_final";
 	match t with
 	| TInst (ccore,_) | TAbstract({a_impl = Some ccore}, _) ->
@@ -1758,10 +1767,10 @@ let patch_class ctx c fields =
 				(* patch arguments types *)
 				(match f.cff_kind with
 				| FFun ff ->
-					let param ((n,opt,t,e) as p) =
+					let param (((n,pn),opt,m,_,e) as p) =
 						try
 							let t2 = (try Hashtbl.find h (("$" ^ f.cff_name ^ "__" ^ n),false) with Not_found -> Hashtbl.find h (("$" ^ n),false)) in
-							n, opt, t2.tp_type, e
+							(n,pn), opt, m, (match t2.tp_type with None -> None | Some t -> Some (t,null_pos)), e
 						with Not_found ->
 							p
 					in
@@ -1777,9 +1786,9 @@ let patch_class ctx c fields =
 					| None -> ()
 					| Some t ->
 						f.cff_kind <- match f.cff_kind with
-						| FVar (_,e) -> FVar (Some t,e)
-						| FProp (get,set,_,eo) -> FProp (get,set,Some t,eo)
-						| FFun f -> FFun { f with f_type = Some t });
+						| FVar (_,e) -> FVar (Some (t,null_pos),e)
+						| FProp (get,set,_,eo) -> FProp (get,set,Some (t,null_pos),eo)
+						| FFun f -> FFun { f with f_type = Some (t,null_pos) });
 					loop (f :: acc) l
 		in
 		List.rev (loop [] fields)
@@ -1796,7 +1805,7 @@ let build_enum_abstract ctx c a fields p =
 			field.cff_meta <- (Meta.Enum,[],field.cff_pos) :: (Meta.Impl,[],field.cff_pos) :: field.cff_meta;
 			let ct = match ct with
 				| Some _ -> ct
-				| None -> Some (TExprToExpr.convert_type (TAbstract(a,List.map snd a.a_params)))
+				| None -> Some (TExprToExpr.convert_type (TAbstract(a,List.map snd a.a_params)),null_pos)
 			in
 			begin match eo with
 				| None ->
@@ -1810,7 +1819,7 @@ let build_enum_abstract ctx c a fields p =
 		| _ ->
 			()
 	) fields;
-	EVars ["",Some (CTAnonymous fields),None],p
+	EVars [("",null_pos),Some (CTAnonymous fields,p),None],p
 
 let is_java_native_function meta = try
 	match Meta.get Meta.Native meta with
@@ -2019,7 +2028,7 @@ module ClassInitializer = struct
 			display_error ctx "Type required for core api classes" p;
 			t_dynamic
 		| _ ->
-			load_type_opt ctx p t
+			load_type_hint ctx t
 
 	let build_fields (ctx,cctx) c fields =
 		let fields = ref fields in
@@ -2028,12 +2037,12 @@ module ClassInitializer = struct
 		c.cl_build <- (fun() -> BuildMacro pending);
 		build_module_def ctx (TClassDecl c) c.cl_meta get_fields cctx.context_init (fun (e,p) ->
 			match e with
-			| EVars [_,Some (CTAnonymous f),None] ->
+			| EVars [_,Some (CTAnonymous f,p),None] ->
 				let f = List.map (fun f ->
 					let f = match cctx.abstract with
 						| Some a ->
-							let a_t = TExprToExpr.convert_type (TAbstract(a,List.map snd a.a_params)) in
-							let this_t = TExprToExpr.convert_type a.a_this in
+							let a_t = TExprToExpr.convert_type' (TAbstract(a,List.map snd a.a_params)) in
+							let this_t = TExprToExpr.convert_type' a.a_this in (* TODO: better pos? *)
 							transform_abstract_field ctx.com this_t a_t a f
 						| None ->
 							f
@@ -2230,7 +2239,7 @@ module ClassInitializer = struct
 				(* TODO is_lib: only load complex type if needed *)
 				let old = ctx.type_params in
 				if fctx.is_static then ctx.type_params <- [];
-				let t = load_complex_type ctx p t in
+				let t = load_complex_type ctx true t in
 				if fctx.is_static then ctx.type_params <- old;
 				t
 		) in
@@ -2387,20 +2396,20 @@ module ClassInitializer = struct
 				c.cl_extern <- false;
 				let texpr = CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = None } in
 				(* ExprOf type parameter might contain platform-specific type, let's replace it by Expr *)
-				let no_expr_of = function
+				let no_expr_of (t,p) = match t with
 					| CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some ("ExprOf"); tparams = [TPType _] }
-					| CTPath { tpackage = []; tname = ("ExprOf"); tsub = None; tparams = [TPType _] } -> Some texpr
-					| t -> Some t
+					| CTPath { tpackage = []; tname = ("ExprOf"); tsub = None; tparams = [TPType _] } -> Some (texpr,p)
+					| t -> Some (t,p)
 				in
 				{
 					f_params = fd.f_params;
-					f_type = (match fd.f_type with None -> Some texpr | Some t -> no_expr_of t);
-					f_args = List.map (fun (a,o,t,e) -> a,o,(match t with None -> Some texpr | Some t -> no_expr_of t),e) fd.f_args;
+					f_type = (match fd.f_type with None -> Some (texpr,null_pos) | Some t -> no_expr_of t);
+					f_args = List.map (fun (a,o,m,t,e) -> a,o,m,(match t with None -> Some (texpr,null_pos) | Some t -> no_expr_of t),e) fd.f_args;
 					f_expr = fd.f_expr;
 				}
 			end else
-				let tdyn = Some (CTPath { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None }) in
-				let to_dyn = function
+				let tdyn = Some (CTPath { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None },null_pos) in
+				let to_dyn p t = match t with
 					| { tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some ("ExprOf"); tparams = [TPType t] } -> Some t
 					| { tpackage = []; tname = ("ExprOf"); tsub = None; tparams = [TPType t] } -> Some t
 					| { tpackage = ["haxe"]; tname = ("PosInfos"); tsub = None; tparams = [] } -> error "haxe.PosInfos is not allowed on macro functions, use Context.currentPos() instead" p
@@ -2408,8 +2417,8 @@ module ClassInitializer = struct
 				in
 				{
 					f_params = fd.f_params;
-					f_type = (match fd.f_type with Some (CTPath t) -> to_dyn t | _ -> tdyn);
-					f_args = List.map (fun (a,o,t,_) -> a,o,(match t with Some (CTPath t) -> to_dyn t | _ -> tdyn),None) fd.f_args;
+					f_type = (match fd.f_type with Some (CTPath t,p) -> to_dyn p t | _ -> tdyn);
+					f_args = List.map (fun (a,o,m,t,_) -> a,o,m,(match t with Some (CTPath t,p) -> to_dyn p t | _ -> tdyn),None) fd.f_args;
 					f_expr = None;
 				}
 		end in
@@ -2422,7 +2431,7 @@ module ClassInitializer = struct
 			| false,FKConstructor ->
 				if fctx.is_static then error "A constructor must not be static" p;
 				begin match fd.f_type with
-					| None | Some (CTPath { tpackage = []; tname = "Void" }) -> ()
+					| None | Some (CTPath { tpackage = []; tname = "Void" },_) -> ()
 					| _ -> error "A class constructor can't have a return value" p;
 				end
 			| false,_ ->
@@ -2439,7 +2448,7 @@ module ClassInitializer = struct
 		(* TODO is_lib: avoid forcing the return type to be typed *)
 		let ret = if fctx.field_kind = FKConstructor then ctx.t.tvoid else type_opt (ctx,cctx) p fd.f_type in
 		let rec loop args = match args with
-			| (name,opt,t,ct) :: args ->
+			| ((name,_),opt,m,t,ct) :: args ->
 				(* TODO is_lib: avoid forcing the field to be typed *)
 				let t, ct = type_function_arg ctx (type_opt (ctx,cctx) p t) ct opt p in
 				delay ctx PTypeField (fun() -> match follow t with
@@ -2527,7 +2536,7 @@ module ClassInitializer = struct
 		let ret = (match t, eo with
 			| None, None -> error (f.cff_name ^ ": Property must either define a type or a default value") p;
 			| None, _ -> mk_mono()
-			| Some t, _ -> load_complex_type ctx p t
+			| Some t, _ -> load_complex_type ctx true t
 		) in
 		let t_get,t_set = match cctx.abstract with
 			| Some a when fctx.is_abstract_member ->
@@ -2944,7 +2953,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 						error "No statics to import from this type" p
 				) :: !context_init
 			))
-	| EUsing t ->
+	| EUsing (t,_) ->
 		(* do the import first *)
 		let types = (match t.tsub with
 			| None ->
@@ -3052,19 +3061,19 @@ let init_module_type ctx context_init do_init (decl,p) =
 					cff_access = [];
 					cff_kind = (match c.ec_args, c.ec_params with
 						| [], [] -> FVar (c.ec_type,None)
-						| _ -> FFun { f_params = c.ec_params; f_type = c.ec_type; f_expr = None; f_args = List.map (fun (n,o,t) -> n,o,Some t,None) c.ec_args });
+						| _ -> FFun { f_params = c.ec_params; f_type = c.ec_type; f_expr = None; f_args = List.map (fun (n,o,t) -> (n,null_pos),o,[],Some t,None) c.ec_args });
 				}
 			) (!constructs)
 		in
 		let init () = List.iter (fun f -> f()) !context_init in
 		build_module_def ctx (TEnumDecl e) e.e_meta get_constructs init (fun (e,p) ->
 			match e with
-			| EVars [_,Some (CTAnonymous fields),None] ->
+			| EVars [_,Some (CTAnonymous fields,p),None] ->
 				constructs := List.map (fun f ->
 					let args, params, t = (match f.cff_kind with
 					| FVar (t,None) -> [], [], t
 					| FFun { f_params = pl; f_type = t; f_expr = (None|Some (EBlock [],_)); f_args = al } ->
-						let al = List.map (fun (n,o,t,_) -> match t with None -> error "Missing function parameter type" f.cff_pos | Some t -> n,o,t) al in
+						let al = List.map (fun ((n,_),o,_,t,_) -> match t with None -> error "Missing function parameter type" f.cff_pos | Some t -> n,o,t) al in
 						al, pl, t
 					| _ ->
 						error "Invalid enum constructor in @:build result" p
@@ -3096,7 +3105,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 			let rt = (match c.ec_type with
 				| None -> et
 				| Some t ->
-					let t = load_complex_type ctx p t in
+					let t = load_complex_type ctx true t in
 					(match follow t with
 					| TEnum (te,_) when te == e ->
 						()
@@ -3109,11 +3118,11 @@ let init_module_type ctx context_init do_init (decl,p) =
 				| l ->
 					is_flat := false;
 					let pnames = ref PMap.empty in
-					TFun (List.map (fun (s,opt,t) ->
+					TFun (List.map (fun (s,opt,(t,tp)) ->
 						(match t with CTPath({tpackage=[];tname="Void"}) -> error "Arguments of type Void are not allowed in enum constructors" c.ec_pos | _ -> ());
 						if PMap.mem s (!pnames) then error ("Duplicate parameter '" ^ s ^ "' in enum constructor " ^ c.ec_name) p;
 						pnames := PMap.add s () (!pnames);
-						s, opt, load_type_opt ~opt ctx p (Some t)
+						s, opt, load_type_hint ~opt ctx (Some (t,tp))
 					) l, rt)
 			) in
 			if PMap.mem c.ec_name e.e_constrs then error ("Duplicate constructor " ^ c.ec_name) p;
@@ -3174,8 +3183,8 @@ let init_module_type ctx context_init do_init (decl,p) =
 		let t = (match get_type d.d_name with TTypeDecl t -> t | _ -> assert false) in
 		check_global_metadata ctx (fun m -> t.t_meta <- m :: t.t_meta) t.t_module.m_path t.t_path None;
 		let ctx = { ctx with type_params = t.t_params } in
-		let tt = load_complex_type ctx p d.d_data in
-		let tt = (match d.d_data with
+		let tt = load_complex_type ctx true d.d_data in
+		let tt = (match fst d.d_data with
 		| CTExtend _ -> tt
 		| CTPath { tpackage = ["haxe";"macro"]; tname = "MacroType" } ->
 			(* we need to follow MacroType immediately since it might define other module types that we will load afterwards *)
@@ -3205,7 +3214,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 		let ctx = { ctx with type_params = a.a_params } in
 		let is_type = ref false in
 		let load_type t from =
-			let t = load_complex_type ctx p t in
+			let t = load_complex_type ctx true t in
 			let t = if not (Meta.has Meta.CoreType a.a_meta) then begin
 				if !is_type then begin
 					let r = exc_protect ctx (fun r ->
@@ -3231,7 +3240,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 			| AIsType t ->
 				if a.a_impl = None then error "Abstracts with underlying type must have an implementation" a.a_pos;
 				if Meta.has Meta.CoreType a.a_meta then error "@:coreType abstracts cannot have an underlying type" p;
-				let at = load_complex_type ctx p t in
+				let at = load_complex_type ctx true t in
 				delay ctx PForce (fun () ->
 					begin match follow at with
 						| TAbstract(a2,_) when a == a2 -> error "Abstract underlying type cannot be recursive" a.a_pos
@@ -3448,10 +3457,10 @@ let parse_module ctx m p =
 							tpackage = !remap;
 							tname = d.d_name;
 							tparams = List.map (fun tp ->
-								TPType (CTPath { tpackage = []; tname = tp.tp_name; tparams = []; tsub = None; })
+								TPType (CTPath { tpackage = []; tname = tp.tp_name; tparams = []; tsub = None; },null_pos)
 							) d.d_params;
 							tsub = None;
-						});
+						}),null_pos;
 				},p) :: acc
 			in
 			match t with
@@ -3527,8 +3536,8 @@ let extend_remoting ctx c t p async prot =
 		| e -> ctx.com.package_rules <- rules; raise e) in
 	ctx.com.package_rules <- rules;
 	let base_fields = [
-		{ cff_name = "__cnx"; cff_pos = p; cff_doc = None; cff_meta = []; cff_access = []; cff_kind = FVar (Some (CTPath { tpackage = ["haxe";"remoting"]; tname = if async then "AsyncConnection" else "Connection"; tparams = []; tsub = None }),None) };
-		{ cff_name = "new"; cff_pos = p; cff_doc = None; cff_meta = []; cff_access = [APublic]; cff_kind = FFun { f_args = ["c",false,None,None]; f_type = None; f_expr = Some (EBinop (OpAssign,(EConst (Ident "__cnx"),p),(EConst (Ident "c"),p)),p); f_params = [] } };
+		{ cff_name = "__cnx"; cff_pos = p; cff_doc = None; cff_meta = []; cff_access = []; cff_kind = FVar (Some (CTPath { tpackage = ["haxe";"remoting"]; tname = if async then "AsyncConnection" else "Connection"; tparams = []; tsub = None },null_pos),None) };
+		{ cff_name = "new"; cff_pos = p; cff_doc = None; cff_meta = []; cff_access = [APublic]; cff_kind = FFun { f_args = [("c",null_pos),false,[],None,None]; f_type = None; f_expr = Some (EBinop (OpAssign,(EConst (Ident "__cnx"),p),(EConst (Ident "c"),p)),p); f_params = [] } };
 	] in
 	let tvoid = CTPath { tpackage = []; tname = "Void"; tparams = []; tsub = None } in
 	let build_field is_public acc f =
@@ -3536,11 +3545,11 @@ let extend_remoting ctx c t p async prot =
 			acc
 		else match f.cff_kind with
 		| FFun fd when (is_public || List.mem APublic f.cff_access) && not (List.mem AStatic f.cff_access) ->
-			if List.exists (fun (_,_,t,_) -> t = None) fd.f_args then error ("Field " ^ f.cff_name ^ " type is not complete and cannot be used by RemotingProxy") p;
-			let eargs = [EArrayDecl (List.map (fun (a,_,_,_) -> (EConst (Ident a),p)) fd.f_args),p] in
-			let ftype = (match fd.f_type with Some (CTPath { tpackage = []; tname = "Void" }) -> None | _ -> fd.f_type) in
+			if List.exists (fun (_,_,_,t,_) -> t = None) fd.f_args then error ("Field " ^ f.cff_name ^ " type is not complete and cannot be used by RemotingProxy") p;
+			let eargs = [EArrayDecl (List.map (fun ((a,_),_,_,_,_) -> (EConst (Ident a),p)) fd.f_args),p] in
+			let ftype = (match fd.f_type with Some (CTPath { tpackage = []; tname = "Void" },_) -> None | _ -> fd.f_type) in
 			let fargs, eargs = if async then match ftype with
-				| Some tret -> fd.f_args @ ["__callb",true,Some (CTFunction ([tret],tvoid)),None], eargs @ [EConst (Ident "__callb"),p]
+				| Some (tret,_) -> fd.f_args @ [("__callb",null_pos),true,[],Some (CTFunction ([tret,null_pos],(tvoid,null_pos)),null_pos),None], eargs @ [EConst (Ident "__callb"),p]
 				| _ -> fd.f_args, eargs @ [EConst (Ident "null"),p]
 			else
 				fd.f_args, eargs
@@ -3718,7 +3727,7 @@ let rec build_generic ctx c p tl =
 	let gctx = make_generic ctx c.cl_params tl p in
 	let name = (snd c.cl_path) ^ "_" ^ gctx.name in
 	try
-		load_instance ctx { tpackage = pack; tname = name; tparams = []; tsub = None } p false
+		load_instance ctx ({ tpackage = pack; tname = name; tparams = []; tsub = None },p) false
 	with Error(Module_not_found path,_) when path = (pack,name) ->
 		let m = (try Hashtbl.find ctx.g.modules (Hashtbl.find ctx.g.types_module c.cl_path) with Not_found -> assert false) in
 		let ctx = { ctx with m = { ctx.m with module_types = m.m_types @ ctx.m.module_types } } in
@@ -3889,7 +3898,7 @@ let rec build_generic ctx c p tl =
 (* HAXE.XML.PROXY *)
 
 let extend_xml_proxy ctx c t file p =
-	let t = load_complex_type ctx p t in
+	let t = load_complex_type ctx false (t,p) in
 	let file = (try Common.find_file ctx.com file with Not_found -> file) in
 	add_dependency c.cl_module (create_fake_module ctx file);
 	let used = ref PMap.empty in
@@ -4034,14 +4043,14 @@ let build_instance ctx mtype p =
 let on_inherit ctx c p (is_extends,tp) =
 	if not is_extends then
 		true
-	else match tp with
-	| { tpackage = ["haxe";"remoting"]; tname = "Proxy"; tparams = [TPType(CTPath t)] } ->
+	else match fst tp with
+	| { tpackage = ["haxe";"remoting"]; tname = "Proxy"; tparams = [TPType(CTPath t,null_pos)] } ->
 		extend_remoting ctx c t p false true;
 		false
-	| { tpackage = ["haxe";"remoting"]; tname = "AsyncProxy"; tparams = [TPType(CTPath t)] } ->
+	| { tpackage = ["haxe";"remoting"]; tname = "AsyncProxy"; tparams = [TPType(CTPath t,null_pos)] } ->
 		extend_remoting ctx c t p true true;
 		false
-	| { tpackage = ["haxe";"xml"]; tname = "Proxy"; tparams = [TPExpr(EConst (String file),p);TPType t] } ->
+	| { tpackage = ["haxe";"xml"]; tname = "Proxy"; tparams = [TPExpr(EConst (String file),p);TPType (t,_)] } ->
 		extend_xml_proxy ctx c t file p;
 		true
 	| _ ->

+ 30 - 30
src/typing/typer.ml

@@ -2820,9 +2820,9 @@ and type_access ctx e p mode =
 		AKExpr (type_expr ctx (e,p) Value)
 
 and type_vars ctx vl p =
-	let vl = List.map (fun (v,t,e) ->
+	let vl = List.map (fun ((v,pv),t,e) ->
 		try
-			let t = Typeload.load_type_opt ctx p t in
+			let t = Typeload.load_type_hint ctx t in
 			let e = (match e with
 				| None -> None
 				| Some e ->
@@ -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 p, e (* TODO: var pos *)
+			add_local ctx v t pv, e
 		with
 			Error (e,p) ->
 				display_error ctx (error_msg e) p;
-				add_local ctx v t_dynamic p, None (* TODO: var pos *)
+				add_local ctx v t_dynamic pv, None
 	) vl in
 	match vl with
 	| [v,eo] ->
@@ -3081,7 +3081,7 @@ and type_object_decl ctx fl with_type p =
 		mk (TBlock (List.rev (e :: (List.rev evars)))) e.etype e.epos
 	)
 
-and type_new ctx t el with_type p =
+and type_new ctx (t,_) el with_type p =
 	let unify_constructor_call c params f ct = match follow ct with
 		| TFun (args,r) ->
 			(try
@@ -3094,10 +3094,10 @@ and type_new ctx t el with_type p =
 			error "Constructor is not a function" p
 	in
 	let t = if t.tparams <> [] then
-		follow (Typeload.load_instance ctx t p false)
+		follow (Typeload.load_instance ctx (t,p) false)
 	else try
 		ctx.call_argument_stack <- el :: ctx.call_argument_stack;
-		let t = follow (Typeload.load_instance ctx t p true) in
+		let t = follow (Typeload.load_instance ctx (t,p) true) in
 		ctx.call_argument_stack <- List.tl ctx.call_argument_stack;
 		(* Try to properly build @:generic classes here (issue #2016) *)
 		begin match t with
@@ -3204,8 +3204,8 @@ and type_try ctx e1 catches with_type p =
 		| x :: _ , _ -> x
 		| [] , name -> name)
 	in
-	let catches = List.fold_left (fun acc (v,t,e) ->
-		let t = Typeload.load_complex_type ctx (pos e) t in
+	let catches = List.fold_left (fun acc ((v,pv),t,e) ->
+		let t = Typeload.load_complex_type ctx true t in
 		let rec loop t = match follow t with
 			| TInst ({ cl_kind = KTypeParameter _} as c,_) when not (Typeload.is_generic_parameter ctx c) ->
 				error "Cannot catch non-generic type parameter" p
@@ -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 (pos e) in (* TODO: var pos *)
+		let v = add_local ctx v t pv in
 		let e = type_expr ctx e with_type in
 		v.v_type <- t2;
 		locals();
@@ -3317,9 +3317,9 @@ and type_local_function ctx name f with_type p =
 	let old_tp,old_in_loop = ctx.type_params,ctx.in_loop in
 	ctx.type_params <- params @ ctx.type_params;
 	if not inline then ctx.in_loop <- false;
-	let rt = Typeload.load_type_opt ctx p f.f_type in
-	let args = List.map (fun (s,opt,t,c) ->
-		let t = Typeload.load_type_opt ctx p t in
+	let rt = Typeload.load_type_hint ctx f.f_type in
+	let args = List.map (fun ((s,_),opt,_,t,c) ->
+		let t = Typeload.load_type_hint ctx t in
 		let t, c = Typeload.type_function_arg ctx t c opt p in
 		s , c, t
 	) f.f_args in
@@ -3486,7 +3486,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			| EBlock [e] -> (EBlock [map_compr e],p)
 			| EParenthesis e2 -> (EParenthesis (map_compr e2),p)
 			| EBinop(OpArrow,a,b) ->
-				et := (ENew({tpackage=[];tname="Map";tparams=[];tsub=None},[]),p);
+				et := (ENew(({tpackage=[];tname="Map";tparams=[];tsub=None},null_pos),[]),p);
 				(ECall ((EField ((EConst (Ident v.v_name),p),"set"),p),[a;b]),p)
 			| _ ->
 				et := (EArrayDecl [],p);
@@ -3652,7 +3652,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		let e = type_expr ctx e Value in
 		mk (TCast (e,None)) (mk_mono()) p
 	| ECast (e, Some t) ->
-		let t = Typeload.load_complex_type ctx (pos e) t in
+		let t = Typeload.load_complex_type ctx true t in
 		let check_param pt = match follow pt with
 			| TMono _ -> () (* This probably means that Dynamic wasn't bound (issue #4675). *)
 			| t when t == t_dynamic -> ()
@@ -3679,8 +3679,8 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		mk (TCast (type_expr ctx e Value,Some texpr)) t p
 	| EDisplay (e,iscall) ->
 		handle_display ctx e iscall with_type p
-	| EDisplayNew t ->
-		let t = Typeload.load_instance ctx t p true in
+	| EDisplayNew (t,_) ->
+		let t = Typeload.load_instance ctx (t,p) true in
 		(match follow t with
 		| TInst (c,params) | TAbstract({a_impl = Some c},params) ->
 			let ct, f = get_constructor ctx c params p in
@@ -3688,7 +3688,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		| _ ->
 			error "Not a class" p)
 	| ECheckType (e,t) ->
-		let t = Typeload.load_complex_type ctx p t in
+		let t = Typeload.load_complex_type ctx true t in
 		let e = type_expr ctx e (WithType t) in
 		let e = Codegen.AbstractCast.cast_or_unify ctx t e p in
 		if e.etype == t then e else mk (TCast (e,None)) t p
@@ -4507,14 +4507,14 @@ let make_macro_api ctx p =
 						{ tpackage = fst path; tname = snd path; tparams = []; tsub = None }
 				in
 				try
-					let m = Some (Typeload.load_instance ctx tp p true) in
+					let m = Some (Typeload.load_instance ctx (tp,p) true) in
 					m
 				with Error (Module_not_found _,p2) when p == p2 ->
 					None
 			)
 		);
 		Interp.resolve_type = (fun t p ->
-			typing_timer ctx true (fun() -> Typeload.load_complex_type ctx p t)
+			typing_timer ctx true (fun() -> Typeload.load_complex_type ctx false (t,p))
 		);
 		Interp.get_module = (fun s ->
 			typing_timer ctx true (fun() ->
@@ -4630,7 +4630,7 @@ let make_macro_api ctx p =
 				let tp = get_type_patch ctx t (Some (f,s)) in
 				match v with
 				| None -> tp.tp_remove <- true
-				| Some _ -> tp.tp_type <- v
+				| Some _ -> tp.tp_type <- Option.map fst v
 			);
 		);
 		Interp.meta_patch = (fun m t f s ->
@@ -4760,7 +4760,7 @@ let make_macro_api ctx p =
 			) types in
 			let pos = (match types with [] -> Ast.null_pos | (_,p) :: _ -> p) in
 			let imports = List.map (fun (il,ik) -> EImport(il,ik),pos) imports in
-			let usings = List.map (fun tp -> EUsing tp,pos) usings in
+			let usings = List.map (fun tp -> EUsing (tp,null_pos),pos) usings in
 			let types = imports @ usings @ types in
 			let mpath = Ast.parse_path m in
 			begin try
@@ -4964,24 +4964,24 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 	let mctx, (margs,mret,mclass,mfield), call_macro = load_macro ctx cpath f p in
 	let mpos = mfield.cf_pos in
 	let ctexpr = { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = None } in
-	let expr = Typeload.load_instance mctx ctexpr p false in
+	let expr = Typeload.load_instance mctx (ctexpr,p) false in
 	(match mode with
 	| MExpr ->
 		unify mctx mret expr mpos;
 	| MBuild ->
-		let ctfields = { tpackage = []; tname = "Array"; tparams = [TPType (CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = Some "Field" })]; tsub = None } in
-		let tfields = Typeload.load_instance mctx ctfields p false in
+		let ctfields = { tpackage = []; tname = "Array"; tparams = [TPType (CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = Some "Field" },null_pos)]; tsub = None } in
+		let tfields = Typeload.load_instance mctx (ctfields,p) false in
 		unify mctx mret tfields mpos
 	| MMacroType ->
 		let cttype = { tpackage = ["haxe";"macro"]; tname = "Type"; tparams = []; tsub = None } in
-		let ttype = Typeload.load_instance mctx cttype p false in
+		let ttype = Typeload.load_instance mctx (cttype,p) false in
 		try
 			unify_raise mctx mret ttype mpos;
 			(* TODO: enable this again in the future *)
 			(* ctx.com.warning "Returning Type from @:genericBuild macros is deprecated, consider returning ComplexType instead" p; *)
 		with Error (Unify _,_) ->
 			let cttype = { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = Some ("ComplexType") } in
-			let ttype = Typeload.load_instance mctx cttype p false in
+			let ttype = Typeload.load_instance mctx (cttype,p) false in
 			unify_raise mctx mret ttype mpos;
 	);
 	(*
@@ -5038,7 +5038,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 			with Error (Custom _,_) ->
 				(* if it's not a constant, let's make something that is typed as haxe.macro.Expr - for nice error reporting *)
 				(EBlock [
-					(EVars ["__tmp",Some (CTPath ctexpr),Some (EConst (Ident "null"),p)],p);
+					(EVars [("__tmp",null_pos),Some (CTPath ctexpr,p),Some (EConst (Ident "null"),p)],p);
 					(EConst (Ident "__tmp"),p);
 				],p)
 			) in
@@ -5091,13 +5091,13 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 						| _ ->
 							List.map Interp.decode_field (Interp.dec_array v)
 					) in
-					(EVars ["fields",Some (CTAnonymous fields),None],p)
+					(EVars [("fields",null_pos),Some (CTAnonymous fields,p),None],p)
 				| MMacroType ->
 					let t = if v = Interp.VNull then
 						mk_mono()
 					else try
 						let ct = Interp.decode_ctype v in
-						Typeload.load_complex_type ctx p ct;
+						Typeload.load_complex_type ctx false ct;
 					with Interp.Invalid_expr ->
 						Interp.decode_type v
 					in

+ 1 - 1
tests/misc/projects/Issue2991/compile.hxml.stderr

@@ -1,3 +1,3 @@
 <list>
-<pos>$$normPath(::cwd::/Main.hx):6: characters 8-24</pos>
+<pos>$$normPath(::cwd::/Main.hx):6: characters 12-13</pos>
 </list>

+ 1 - 1
tests/misc/projects/Issue2993/compile.hxml.stderr

@@ -1,3 +1,3 @@
 <list>
-<pos>$$normPath(::cwd::/Main.hx):2: lines 2-5</pos>
+<pos>$$normPath(::cwd::/Main.hx):2: characters 15-18</pos>
 </list>

+ 1 - 1
tests/misc/projects/Issue3710/compile-1-fail.hxml.stderr

@@ -1 +1 @@
-Main1.hx:3: characters 2-23 : Invalid number of type parameters for A
+Main1.hx:3: characters 8-22 : Invalid number of type parameters for A

+ 1 - 1
tests/misc/projects/Issue3710/compile-2-fail.hxml.stderr

@@ -1 +1 @@
-Main2.hx:3: characters 2-18 : Invalid number of type parameters for A
+Main2.hx:3: characters 8-17 : Invalid number of type parameters for A