Browse Source

position ALL the things

Simon Krajewski 9 years ago
parent
commit
56fae7a1de

+ 30 - 16
src/display/display.ml

@@ -5,6 +5,7 @@ open Type
 exception DocumentSymbols of string
 exception DocumentSymbols of string
 exception DisplayTypes of t list
 exception DisplayTypes of t list
 exception DisplayPosition of Ast.pos list
 exception DisplayPosition of Ast.pos list
+exception DisplaySubExpression of Ast.expr
 
 
 let is_display_file p =
 let is_display_file p =
 	Common.unique_full_path p.pfile = (!Parser.resume_display).pfile
 	Common.unique_full_path p.pfile = (!Parser.resume_display).pfile
@@ -78,14 +79,21 @@ let find_before_pos com e =
 	map e
 	map e
 
 
 let display_type dm t =
 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])
-	| _ -> ()
+	try
+		let mt = module_type_of_type t in
+		begin 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])
+			| _ -> ()
+		end
+	with Exit ->
+		()
+
+let display_module_type dm mt =
+	display_type dm (type_of_module_type mt)
 
 
 let display_variable dm v = match dm with
 let display_variable dm v = match dm with
 	| DMPosition -> raise (DisplayPosition [v.v_pos])
 	| DMPosition -> raise (DisplayPosition [v.v_pos])
@@ -93,6 +101,12 @@ let display_variable dm v = match dm with
 	| DMType -> raise (DisplayTypes [v.v_type])
 	| DMType -> raise (DisplayTypes [v.v_type])
 	| _ -> ()
 	| _ -> ()
 
 
+let display_field dm cf = match dm with
+	| DMPosition -> raise (DisplayPosition [cf.cf_pos]);
+	| DMUsage -> cf.cf_meta <- (Meta.Usage,[],cf.cf_pos) :: cf.cf_meta;
+	| DMType -> raise (DisplayTypes [cf.cf_type])
+	| _ -> ()
+
 module SymbolKind = struct
 module SymbolKind = struct
 	type t =
 	type t =
 		| File
 		| File
@@ -224,34 +238,34 @@ let print_document_symbols (pack,decls) =
 	in
 	in
 	let field si_type cff = match cff.cff_kind with
 	let field si_type cff = match cff.cff_kind with
 		| FVar(_,eo) ->
 		| FVar(_,eo) ->
-			let si_field = add cff.cff_name Field cff.cff_pos (Some si_type) in
+			let si_field = add (fst cff.cff_name) Field (pos cff.cff_name) (Some si_type) in
 			expr_opt (Some si_field) eo
 			expr_opt (Some si_field) eo
 		| FFun f ->
 		| FFun f ->
-			let si_method = add cff.cff_name (if cff.cff_name = "new" then Constructor else Method) cff.cff_pos (Some si_type) in
+			let si_method = add (fst cff.cff_name) (if fst cff.cff_name = "new" then Constructor else Method) (pos cff.cff_name) (Some si_type) in
 			func si_method f
 			func si_method f
 		| FProp(_,_,_,eo) ->
 		| FProp(_,_,_,eo) ->
-			let si_property = add cff.cff_name Property cff.cff_pos (Some si_type) in
+			let si_property = add (fst cff.cff_name) Property (pos cff.cff_name) (Some si_type) in
 			expr_opt (Some si_property) eo
 			expr_opt (Some si_property) eo
 	in
 	in
 	List.iter (fun (td,p) -> match td with
 	List.iter (fun (td,p) -> match td with
 		| EImport _ | EUsing _ ->
 		| EImport _ | EUsing _ ->
 			() (* TODO: Can we do anything with these? *)
 			() (* TODO: Can we do anything with these? *)
 		| EClass d ->
 		| EClass d ->
-			let si_type = add d.d_name (if List.mem HInterface d.d_flags then Interface else Class) p si_pack in
+			let si_type = add (fst d.d_name) (if List.mem HInterface d.d_flags then Interface else Class) (pos d.d_name) si_pack in
 			List.iter (field si_type) d.d_data
 			List.iter (field si_type) d.d_data
 		| EEnum d ->
 		| EEnum d ->
-			let si_type = add d.d_name Enum p si_pack in
+			let si_type = add (fst d.d_name) Enum (pos d.d_name) si_pack in
 			List.iter (fun ef ->
 			List.iter (fun ef ->
-				ignore (add ef.ec_name Method ef.ec_pos (Some si_type))
+				ignore (add (fst ef.ec_name) Method (pos ef.ec_name) (Some si_type))
 			) d.d_data
 			) d.d_data
 		| ETypedef d ->
 		| ETypedef d ->
-			let si_type = add d.d_name Interface p si_pack in
+			let si_type = add (fst d.d_name) Interface (pos d.d_name) si_pack in
 			(match d.d_data with
 			(match d.d_data with
 			| CTAnonymous fields,_ ->
 			| CTAnonymous fields,_ ->
 				List.iter (field si_type) fields
 				List.iter (field si_type) fields
 			| _ -> ())
 			| _ -> ())
 		| EAbstract d ->
 		| EAbstract d ->
-			let si_type = add d.d_name Class p si_pack in
+			let si_type = add (fst d.d_name) Class (pos d.d_name) si_pack in
 			List.iter (field si_type) d.d_data
 			List.iter (field si_type) d.d_data
 	) decls;
 	) decls;
 	let jl = List.map (fun si ->
 	let jl = List.map (fun si ->

+ 15 - 15
src/generators/gencs.ml

@@ -3581,14 +3581,14 @@ let convert_ilenum ctx p ?(is_flag=false) ilcls =
 				| _ ->
 				| _ ->
 					[], Int64.zero
 					[], Int64.zero
 			in
 			in
-			data := ( { ec_name = f.fname; ec_doc = None; ec_meta = meta; ec_args = []; ec_pos = p; ec_params = []; ec_type = None; }, const) :: !data;
+			data := ( { ec_name = f.fname,null_pos; ec_doc = None; ec_meta = meta; ec_args = []; ec_pos = p; ec_params = []; ec_type = None; }, const) :: !data;
 	) ilcls.cfields;
 	) ilcls.cfields;
 	let data = List.stable_sort (fun (_,i1) (_,i2) -> Int64.compare i1 i2) (List.rev !data) in
 	let data = List.stable_sort (fun (_,i1) (_,i2) -> Int64.compare i1 i2) (List.rev !data) in
 
 
 	let _, c = netpath_to_hx ctx.nstd ilcls.cpath in
 	let _, c = netpath_to_hx ctx.nstd ilcls.cpath in
 	let name = netname_to_hx c in
 	let name = netname_to_hx c in
 	EEnum {
 	EEnum {
-		d_name = if is_flag then name ^ "_FlagsEnum" else name;
+		d_name = (if is_flag then name ^ "_FlagsEnum" else name),null_pos;
 		d_doc = None;
 		d_doc = None;
 		d_params = []; (* enums never have type parameters *)
 		d_params = []; (* enums never have type parameters *)
 		d_meta = !meta;
 		d_meta = !meta;
@@ -3647,7 +3647,7 @@ let convert_ilfield ctx p field =
 			cff_name, !cff_meta
 			cff_name, !cff_meta
 	in
 	in
 	{
 	{
-		cff_name = cff_name;
+		cff_name = cff_name,null_pos;
 		cff_doc = cff_doc;
 		cff_doc = cff_doc;
 		cff_pos = cff_pos;
 		cff_pos = cff_pos;
 		cff_meta = cff_meta;
 		cff_meta = cff_meta;
@@ -3675,7 +3675,7 @@ let convert_ilevent ctx p ev =
 	let acc = add_m acc ev.eremove in
 	let acc = add_m acc ev.eremove in
 	let acc = add_m acc ev.eraise in
 	let acc = add_m acc ev.eraise in
 	{
 	{
-		cff_name = name;
+		cff_name = name,null_pos;
 		cff_doc = None;
 		cff_doc = None;
 		cff_pos = p;
 		cff_pos = p;
 		cff_meta = meta;
 		cff_meta = meta;
@@ -3776,7 +3776,7 @@ let convert_ilmethod ctx p m is_explicit_impl =
 		let ret = convert_signature ctx p (change_sig ret) in
 		let ret = convert_signature ctx p (change_sig ret) in
 		let types = List.map (fun t ->
 		let types = List.map (fun t ->
 			{
 			{
-				tp_name = "M" ^ string_of_int t.tnumber;
+				tp_name = "M" ^ string_of_int t.tnumber,null_pos;
 				tp_params = [];
 				tp_params = [];
 				tp_constraints = [];
 				tp_constraints = [];
 				tp_meta = [];
 				tp_meta = [];
@@ -3809,7 +3809,7 @@ let convert_ilmethod ctx p m is_explicit_impl =
 			| _ -> acc
 			| _ -> acc
 	in
 	in
 	{
 	{
-		cff_name = cff_name;
+		cff_name = cff_name,null_pos;
 		cff_doc = cff_doc;
 		cff_doc = cff_doc;
 		cff_pos = cff_pos;
 		cff_pos = cff_pos;
 		cff_meta = cff_meta;
 		cff_meta = cff_meta;
@@ -3873,7 +3873,7 @@ let convert_ilprop ctx p prop is_explicit_impl =
 		FProp (get, set, Some(convert_signature ctx p ilsig,null_pos), None)
 		FProp (get, set, Some(convert_signature ctx p ilsig,null_pos), None)
 	in
 	in
 	{
 	{
-		cff_name = prop.pname;
+		cff_name = prop.pname,null_pos;
 		cff_doc = None;
 		cff_doc = None;
 		cff_pos = p;
 		cff_pos = p;
 		cff_meta = meta;
 		cff_meta = meta;
@@ -3907,7 +3907,7 @@ let mk_metas metas p =
 let mk_abstract_fun name p kind metas acc =
 let mk_abstract_fun name p kind metas acc =
 	let metas = mk_metas metas p in
 	let metas = mk_metas metas p in
 	{
 	{
-		cff_name = name;
+		cff_name = name,null_pos;
 		cff_doc = None;
 		cff_doc = None;
 		cff_pos = p;
 		cff_pos = p;
 		cff_meta = metas;
 		cff_meta = metas;
@@ -3945,7 +3945,7 @@ let convert_delegate ctx p ilcls =
 	let haxe_type = convert_fun ctx p ret args in
 	let haxe_type = convert_fun ctx p ret args in
 	let types = List.map (fun t ->
 	let types = List.map (fun t ->
 		{
 		{
-			tp_name = "T" ^ string_of_int t.tnumber;
+			tp_name = ("T" ^ string_of_int t.tnumber),null_pos;
 			tp_params = [];
 			tp_params = [];
 			tp_constraints = [];
 			tp_constraints = [];
 			tp_meta = [];
 			tp_meta = [];
@@ -3967,7 +3967,7 @@ let convert_delegate ctx p ilcls =
 	let mk_op op name =
 	let mk_op op name =
 		let p = { p with pfile = p.pfile ^" (op " ^ name ^ ")" } in
 		let p = { p with pfile = p.pfile ^" (op " ^ name ^ ")" } in
 		{
 		{
-			cff_name = name;
+			cff_name = name,null_pos;
 			cff_doc = None;
 			cff_doc = None;
 			cff_pos = p;
 			cff_pos = p;
 			cff_meta = [ Meta.Extern,[],p ; Meta.Op, [ (EBinop(op, (EConst(Ident"A"),p), (EConst(Ident"B"),p)),p) ], p ];
 			cff_meta = [ Meta.Extern,[],p ; Meta.Op, [ (EBinop(op, (EConst(Ident"A"),p), (EConst(Ident"B"),p)),p) ], p ];
@@ -3976,7 +3976,7 @@ let convert_delegate ctx p ilcls =
 		}
 		}
 	in
 	in
 	let params = (List.map (fun s ->
 	let params = (List.map (fun s ->
-		TPType (mk_type_path ctx ([],[],s.tp_name) [],null_pos)
+		TPType (mk_type_path ctx ([],[],fst s.tp_name) [],null_pos)
 	) types) in
 	) types) in
 	let underlying_type = match ilcls.cpath with
 	let underlying_type = match ilcls.cpath with
 		| ns,inner,name ->
 		| ns,inner,name ->
@@ -4008,7 +4008,7 @@ let convert_delegate ctx p ilcls =
 	let fn_asdel = mk_abstract_fun "AsDelegate" p fn_asdel [Meta.Extern] [APublic;AInline] in
 	let fn_asdel = mk_abstract_fun "AsDelegate" p fn_asdel [Meta.Extern] [APublic;AInline] in
 	let _, c = netpath_to_hx ctx.nstd ilcls.cpath in
 	let _, c = netpath_to_hx ctx.nstd ilcls.cpath in
 	EAbstract {
 	EAbstract {
-		d_name = netname_to_hx c;
+		d_name = netname_to_hx c,null_pos;
 		d_doc = None;
 		d_doc = None;
 		d_params = types;
 		d_params = types;
 		d_meta = mk_metas [Meta.Delegate; Meta.Forward] p;
 		d_meta = mk_metas [Meta.Delegate; Meta.Forward] p;
@@ -4109,7 +4109,7 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 
 
 			let params = List.map (fun p ->
 			let params = List.map (fun p ->
 				{
 				{
-					tp_name = "T" ^ string_of_int p.tnumber;
+					tp_name = "T" ^ string_of_int p.tnumber,null_pos;
 					tp_params = [];
 					tp_params = [];
 					tp_constraints = [];
 					tp_constraints = [];
 					tp_meta = [];
 					tp_meta = [];
@@ -4122,7 +4122,7 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 				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 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 =
 				let op name =
 					{
 					{
-						cff_name = name;
+						cff_name = name,null_pos;
 						cff_doc = None;
 						cff_doc = None;
 						cff_pos = p;
 						cff_pos = p;
 						cff_meta = [];
 						cff_meta = [];
@@ -4144,7 +4144,7 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 			in
 			in
 			let _, c = netpath_to_hx ctx.nstd path in
 			let _, c = netpath_to_hx ctx.nstd path in
 			EClass {
 			EClass {
-				d_name = netname_to_hx c;
+				d_name = netname_to_hx c,null_pos;
 				d_doc = None;
 				d_doc = None;
 				d_params = params;
 				d_params = params;
 				d_meta = !meta;
 				d_meta = !meta;

+ 16 - 16
src/generators/genjava.ml

@@ -2737,7 +2737,7 @@ let convert_param ctx p parent param =
 		in
 		in
 		let constraints = List.map (fun s -> if same_sig parent s then (TObject( (["java";"lang"], "Object"), [])) else s) constraints in
 		let constraints = List.map (fun s -> if same_sig parent s then (TObject( (["java";"lang"], "Object"), [])) else s) constraints in
 		{
 		{
-			tp_name = name;
+			tp_name = name,null_pos;
 			tp_params = [];
 			tp_params = [];
 			tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) constraints;
 			tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) constraints;
 			tp_meta = [];
 			tp_meta = [];
@@ -2764,12 +2764,12 @@ let convert_java_enum ctx p pe =
 		(* if List.mem JEnum f.jf_flags then *)
 		(* if List.mem JEnum f.jf_flags then *)
 		match f.jf_vmsignature with
 		match f.jf_vmsignature with
 		| TObject( path, [] ) when path = pe.cpath && List.mem JStatic f.jf_flags && List.mem JFinal f.jf_flags ->
 		| TObject( path, [] ) when path = pe.cpath && List.mem JStatic f.jf_flags && List.mem JFinal f.jf_flags ->
-			data := { ec_name = f.jf_name; ec_doc = None; ec_meta = []; ec_args = []; ec_pos = p; ec_params = []; ec_type = None; } :: !data;
+			data := { ec_name = f.jf_name,null_pos; ec_doc = None; ec_meta = []; ec_args = []; ec_pos = p; ec_params = []; ec_type = None; } :: !data;
 		| _ -> ()
 		| _ -> ()
 	) pe.cfields;
 	) pe.cfields;
 
 
 	EEnum {
 	EEnum {
-		d_name = jname_to_hx (snd pe.cpath);
+		d_name = jname_to_hx (snd pe.cpath),null_pos;
 		d_doc = None;
 		d_doc = None;
 		d_params = []; (* enums never have type parameters *)
 		d_params = []; (* enums never have type parameters *)
 		d_meta = !meta;
 		d_meta = !meta;
@@ -2858,14 +2858,14 @@ let convert_java_enum ctx p pe =
 					let types = List.map (function
 					let types = List.map (function
 						| (name, Some ext, impl) ->
 						| (name, Some ext, impl) ->
 							{
 							{
-								tp_name = name;
+								tp_name = name,null_pos;
 								tp_params = [];
 								tp_params = [];
 								tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) (ext :: impl);
 								tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) (ext :: impl);
 								tp_meta = [];
 								tp_meta = [];
 							}
 							}
 						| (name, None, impl) ->
 						| (name, None, impl) ->
 							{
 							{
-								tp_name = name;
+								tp_name = name,null_pos;
 								tp_params = [];
 								tp_params = [];
 								tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) (impl);
 								tp_constraints = List.map (fun t -> convert_signature ctx p t,null_pos) (impl);
 								tp_meta = [];
 								tp_meta = [];
@@ -2903,7 +2903,7 @@ let convert_java_enum ctx p pe =
 			Printf.printf "\t%s%sfield %s : %s\n" (if List.mem AStatic !cff_access then "static " else "") (if List.mem AOverride !cff_access then "override " else "") cff_name (s_sig field.jf_signature);
 			Printf.printf "\t%s%sfield %s : %s\n" (if List.mem AStatic !cff_access then "static " else "") (if List.mem AOverride !cff_access then "override " else "") cff_name (s_sig field.jf_signature);
 
 
 		{
 		{
-			cff_name = cff_name;
+			cff_name = cff_name,null_pos;
 			cff_doc = cff_doc;
 			cff_doc = cff_doc;
 			cff_pos = cff_pos;
 			cff_pos = cff_pos;
 			cff_meta = cff_meta;
 			cff_meta = cff_meta;
@@ -3006,7 +3006,7 @@ let convert_java_enum ctx p pe =
 			) jc.cmethods) in
 			) jc.cmethods) in
 
 
 			(EClass {
 			(EClass {
-				d_name = jname_to_hx (snd jc.cpath);
+				d_name = jname_to_hx (snd jc.cpath),null_pos;
 				d_doc = None;
 				d_doc = None;
 				d_params = List.map (convert_param ctx p jc.cpath) jc.ctypes;
 				d_params = List.map (convert_param ctx p jc.cpath) jc.ctypes;
 				d_meta = !meta;
 				d_meta = !meta;
@@ -3539,11 +3539,11 @@ let add_java_lib com file std =
 		in
 		in
 		match decl with
 		match decl with
 			| EClass c ->
 			| EClass c ->
-				EClass { c with d_meta = add_meta c.d_name c.d_meta }
+				EClass { c with d_meta = add_meta (fst c.d_name) c.d_meta }
 			| EEnum e ->
 			| EEnum e ->
-				EEnum { e with d_meta = add_meta e.d_name e.d_meta }
+				EEnum { e with d_meta = add_meta (fst e.d_name) e.d_meta }
 			| EAbstract a ->
 			| EAbstract a ->
-				EAbstract { a with d_meta = add_meta a.d_name a.d_meta }
+				EAbstract { a with d_meta = add_meta (fst a.d_name) a.d_meta }
 			| d -> d
 			| d -> d
 	in
 	in
 	let rec build ctx path p types =
 	let rec build ctx path p types =
@@ -3604,7 +3604,7 @@ let add_java_lib com file std =
 								let ncls = convert_java_class ctx pos { cls with cmethods = smethods; cfields = sfields; cflags = []; csuper = obj; cinterfaces = []; cinner_types = []; ctypes = [] } in
 								let ncls = convert_java_class ctx pos { cls with cmethods = smethods; cfields = sfields; cflags = []; csuper = obj; cinterfaces = []; cinner_types = []; ctypes = [] } in
 								match ncls with
 								match ncls with
 								| EClass c :: imports ->
 								| EClass c :: imports ->
-									(EClass { c with d_name = c.d_name ^ "_Statics" }, pos) :: inner @ List.map (fun i -> i,pos) imports
+									(EClass { c with d_name = (fst c.d_name ^ "_Statics"),snd c.d_name }, pos) :: inner @ List.map (fun i -> i,pos) imports
 								| _ -> assert false
 								| _ -> assert false
 							with | Not_found ->
 							with | Not_found ->
 								inner
 								inner
@@ -3613,20 +3613,20 @@ let add_java_lib com file std =
 							List.iter (fun x ->
 							List.iter (fun x ->
 								match fst x with
 								match fst x with
 								| EClass c ->
 								| EClass c ->
-									inner_alias := SS.add c.d_name !inner_alias;
+									inner_alias := SS.add (fst c.d_name) !inner_alias;
 								| _ -> ()
 								| _ -> ()
 							) inner;
 							) inner;
 							let alias_list = ref [] in
 							let alias_list = ref [] in
 							List.iter (fun x ->
 							List.iter (fun x ->
 								match x with
 								match x with
 								| (EClass c, pos) -> begin
 								| (EClass c, pos) -> begin
-									let parts = String.nsplit c.d_name "_24" in
+									let parts = String.nsplit (fst c.d_name) "_24" in
 									match parts with
 									match parts with
 										| _ :: _ ->
 										| _ :: _ ->
 											let alias_name = String.concat "_" parts in
 											let alias_name = String.concat "_" parts in
 											if (not (SS.mem alias_name !inner_alias)) && (not (String.exists (snd path) "_24")) then begin
 											if (not (SS.mem alias_name !inner_alias)) && (not (String.exists (snd path) "_24")) then begin
 												let alias_def = ETypedef {
 												let alias_def = ETypedef {
-													d_name = alias_name;
+													d_name = alias_name,null_pos;
 													d_doc = None;
 													d_doc = None;
 													d_params = c.d_params;
 													d_params = c.d_params;
 													d_meta = [];
 													d_meta = [];
@@ -3637,12 +3637,12 @@ let add_java_lib com file std =
 														tparams = List.map (fun tp ->
 														tparams = List.map (fun tp ->
 															TPType (CTPath {
 															TPType (CTPath {
 																tpackage = [];
 																tpackage = [];
-																tname = tp.tp_name;
+																tname = fst tp.tp_name;
 																tparams = [];
 																tparams = [];
 																tsub = None;
 																tsub = None;
 															},null_pos)
 															},null_pos)
 														) c.d_params;
 														) c.d_params;
-														tsub = Some(c.d_name);
+														tsub = Some(fst c.d_name);
 													},null_pos;
 													},null_pos;
 												} in
 												} in
 												inner_alias := SS.add alias_name !inner_alias;
 												inner_alias := SS.add alias_name !inner_alias;

+ 7 - 7
src/generators/genswf.ml

@@ -122,7 +122,7 @@ let build_class com c file =
 	match path with
 	match path with
 	| { tpackage = ["flash";"utils"]; tname = ("Object"|"Function") } ->
 	| { tpackage = ["flash";"utils"]; tname = ("Object"|"Function") } ->
 		let inf = {
 		let inf = {
-			d_name = path.tname;
+			d_name = path.tname,null_pos;
 			d_doc = None;
 			d_doc = None;
 			d_params = [];
 			d_params = [];
 			d_meta = [];
 			d_meta = [];
@@ -186,7 +186,7 @@ let build_class com c file =
 			List.map (fun (s,cl) -> s, List.map (fun c -> EConst c,pos) cl, pos) (!meta)
 			List.map (fun (s,cl) -> s, List.map (fun c -> EConst c,pos) cl, pos) (!meta)
 		in
 		in
 		let cf = {
 		let cf = {
-			cff_name = name;
+			cff_name = name,null_pos;
 			cff_doc = None;
 			cff_doc = None;
 			cff_pos = pos;
 			cff_pos = pos;
 			cff_meta = mk_meta();
 			cff_meta = mk_meta();
@@ -296,7 +296,7 @@ let build_class com c file =
 		let flags = [APublic] in
 		let flags = [APublic] in
 		let flags = if stat then AStatic :: flags else flags in
 		let flags = if stat then AStatic :: flags else flags in
 		{
 		{
-			cff_name = name;
+			cff_name = name,null_pos;
 			cff_pos = pos;
 			cff_pos = pos;
 			cff_doc = None;
 			cff_doc = None;
 			cff_access = flags;
 			cff_access = flags;
@@ -335,7 +335,7 @@ let build_class com c file =
 						ec_doc = None;
 						ec_doc = None;
 						ec_type = None;
 						ec_type = None;
 					} :: loop l
 					} :: loop l
-				| FFun { f_args = [] } when f.cff_name = "new" -> loop l
+				| FFun { f_args = [] } when fst f.cff_name = "new" -> loop l
 				| _ -> raise Exit
 				| _ -> raise Exit
 		in
 		in
 		List.iter (function HExtends _ | HImplements _ -> raise Exit | _ -> ()) flags;
 		List.iter (function HExtends _ | HImplements _ -> raise Exit | _ -> ()) flags;
@@ -343,7 +343,7 @@ let build_class com c file =
 		let name = "fakeEnum:" ^ String.concat "." (path.tpackage @ [path.tname]) in
 		let name = "fakeEnum:" ^ String.concat "." (path.tpackage @ [path.tname]) in
 		if not (Common.raw_defined com name) then raise Exit;
 		if not (Common.raw_defined com name) then raise Exit;
 		let enum_data = {
 		let enum_data = {
-			d_name = path.tname;
+			d_name = path.tname,null_pos;
 			d_doc = None;
 			d_doc = None;
 			d_params = [];
 			d_params = [];
 			d_meta = [(Meta.FakeEnum,[EConst (Ident !real_type),pos],pos)];
 			d_meta = [(Meta.FakeEnum,[EConst (Ident !real_type),pos],pos)];
@@ -353,10 +353,10 @@ let build_class com c file =
 		(path.tpackage, [(EEnum enum_data,pos)])
 		(path.tpackage, [(EEnum enum_data,pos)])
 	with Exit ->
 	with Exit ->
 	let class_data = {
 	let class_data = {
-		d_name = path.tname;
+		d_name = path.tname,null_pos;
 		d_doc = None;
 		d_doc = None;
 		d_params = [];
 		d_params = [];
-		d_meta = if c.hlc_final && List.exists (fun f -> f.cff_name <> "new" && not (List.mem AStatic f.cff_access)) fields then [Meta.Final,[],pos] else [];
+		d_meta = if c.hlc_final && List.exists (fun f -> fst f.cff_name <> "new" && not (List.mem AStatic f.cff_access)) fields then [Meta.Final,[],pos] else [];
 		d_flags = flags;
 		d_flags = flags;
 		d_data = fields;
 		d_data = fields;
 	} in
 	} in

+ 6 - 6
src/macro/interp.ml

@@ -3986,7 +3986,7 @@ and encode_field (f:class_field) =
 		| FProp (get,set, t, e) -> 2, [enc_string get; enc_string set; null encode_ctype t; null encode_expr e]
 		| FProp (get,set, t, e) -> 2, [enc_string get; enc_string set; null encode_ctype t; null encode_expr e]
 	in
 	in
 	enc_obj [
 	enc_obj [
-		"name",enc_string f.cff_name;
+		"name",encode_placed_name f.cff_name;
 		"doc", null enc_string f.cff_doc;
 		"doc", null enc_string f.cff_doc;
 		"pos", encode_pos f.cff_pos;
 		"pos", encode_pos f.cff_pos;
 		"kind", enc_enum IField tag pl;
 		"kind", enc_enum IField tag pl;
@@ -4013,7 +4013,7 @@ and encode_ctype t =
 
 
 and encode_tparam_decl tp =
 and encode_tparam_decl tp =
 	enc_obj [
 	enc_obj [
-		"name", enc_string tp.tp_name;
+		"name", encode_placed_name tp.tp_name;
 		"params", enc_array (List.map encode_tparam_decl tp.tp_params);
 		"params", enc_array (List.map encode_tparam_decl tp.tp_params);
 		"constraints", enc_array (List.map encode_ctype tp.tp_constraints);
 		"constraints", enc_array (List.map encode_ctype tp.tp_constraints);
 		"meta", encode_meta_content tp.tp_meta;
 		"meta", encode_meta_content tp.tp_meta;
@@ -4254,7 +4254,7 @@ and decode_tparams = function
 
 
 and decode_tparam_decl v =
 and decode_tparam_decl v =
 	{
 	{
-		tp_name = dec_string (field v "name");
+		tp_name = decode_placed_name (field v "name");
 		tp_constraints = (match field v "constraints" with VNull -> [] | a -> List.map decode_ctype (dec_array a));
 		tp_constraints = (match field v "constraints" with VNull -> [] | a -> List.map decode_ctype (dec_array a));
 		tp_params = decode_tparams (field v "params");
 		tp_params = decode_tparams (field v "params");
 		tp_meta = decode_meta_content (field v "meta");
 		tp_meta = decode_meta_content (field v "meta");
@@ -4300,7 +4300,7 @@ and decode_field v =
 			raise Invalid_expr
 			raise Invalid_expr
 	in
 	in
 	{
 	{
-		cff_name = dec_string (field v "name");
+		cff_name = decode_placed_name (field v "name");
 		cff_doc = opt dec_string (field v "doc");
 		cff_doc = opt dec_string (field v "doc");
 		cff_pos = decode_pos (field v "pos");
 		cff_pos = decode_pos (field v "pos");
 		cff_kind = fkind;
 		cff_kind = fkind;
@@ -4991,7 +4991,7 @@ let rec decode_texpr v =
 
 
 let decode_type_def v =
 let decode_type_def v =
 	let pack = List.map dec_string (dec_array (field v "pack")) in
 	let pack = List.map dec_string (dec_array (field v "pack")) in
-	let name = dec_string (field v "name") in
+	let name = decode_placed_name (field v "name") in
 	let meta = decode_meta_content (field v "meta") in
 	let meta = decode_meta_content (field v "meta") in
 	let pos = decode_pos (field v "pos") in
 	let pos = decode_pos (field v "pos") in
 	let isExtern = (match field v "isExtern" with VNull -> false | v -> dec_bool v) in
 	let isExtern = (match field v "isExtern" with VNull -> false | v -> dec_bool v) in
@@ -5051,7 +5051,7 @@ let decode_type_def v =
 	(* if our package ends with an uppercase letter, then it's the module name *)
 	(* if our package ends with an uppercase letter, then it's the module name *)
 	let pack,name = (match List.rev pack with
 	let pack,name = (match List.rev pack with
 		| last :: l when not (is_lower_ident last) -> List.rev l, last
 		| last :: l when not (is_lower_ident last) -> List.rev l, last
-		| _ -> pack, name
+		| _ -> pack, fst name
 	) in
 	) in
 	(pack, name), tdef, pos
 	(pack, name), tdef, pos
 
 

+ 8 - 8
src/syntax/ast.ml

@@ -379,7 +379,7 @@ and expr_def =
 and expr = expr_def * pos
 and expr = expr_def * pos
 
 
 and type_param = {
 and type_param = {
-	tp_name : string;
+	tp_name : placed_name;
 	tp_params :	type_param list;
 	tp_params :	type_param list;
 	tp_constraints : type_hint list;
 	tp_constraints : type_hint list;
 	tp_meta : metadata;
 	tp_meta : metadata;
@@ -405,7 +405,7 @@ and class_field_kind =
 	| FProp of string * string * type_hint option * expr option
 	| FProp of string * string * type_hint option * expr option
 
 
 and class_field = {
 and class_field = {
-	cff_name : string;
+	cff_name : placed_name;
 	cff_doc : documentation;
 	cff_doc : documentation;
 	cff_pos : pos;
 	cff_pos : pos;
 	mutable cff_meta : metadata;
 	mutable cff_meta : metadata;
@@ -432,7 +432,7 @@ type abstract_flag =
 	| AExtern
 	| AExtern
 
 
 type enum_constructor = {
 type enum_constructor = {
-	ec_name : string;
+	ec_name : placed_name;
 	ec_doc : documentation;
 	ec_doc : documentation;
 	ec_meta : metadata;
 	ec_meta : metadata;
 	ec_args : (string * bool * type_hint) list;
 	ec_args : (string * bool * type_hint) list;
@@ -442,7 +442,7 @@ type enum_constructor = {
 }
 }
 
 
 type ('a,'b) definition = {
 type ('a,'b) definition = {
-	d_name : string;
+	d_name : placed_name;
 	d_doc : documentation;
 	d_doc : documentation;
 	d_params : type_param list;
 	d_params : type_param list;
 	d_meta : metadata;
 	d_meta : metadata;
@@ -867,9 +867,9 @@ 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_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 "" ^
 		if List.length f.cff_access > 0 then String.concat " " (List.map s_access f.cff_access) else "" ^
 		match f.cff_kind with
 		match f.cff_kind with
-		| 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
+		| FVar (t,e) -> "var " ^ (fst f.cff_name) ^ s_opt_type_hint tabs t " : " ^ s_opt_expr tabs e " = "
+		| FProp (get,set,t,e) -> "var " ^ (fst f.cff_name) ^ "(" ^ get ^ "," ^ set ^ ")" ^ s_opt_type_hint tabs t " : " ^ s_opt_expr tabs e " = "
+		| FFun func -> "function " ^ (fst f.cff_name) ^ s_func tabs func
 	and s_metadata tabs (s,e,_) =
 	and s_metadata tabs (s,e,_) =
 		"@" ^ Meta.to_string s ^ if List.length e > 0 then "(" ^ s_expr_list tabs e ", " ^ ")" else ""
 		"@" ^ Meta.to_string s ^ if List.length e > 0 then "(" ^ s_expr_list tabs e ", " ^ ")" else ""
 	and s_opt_expr tabs e pre =
 	and s_opt_expr tabs e pre =
@@ -886,7 +886,7 @@ let s_expr e =
 		s_opt_type_hint tabs f.f_type ":" ^
 		s_opt_type_hint tabs f.f_type ":" ^
 		s_opt_expr tabs f.f_expr " "
 		s_opt_expr tabs f.f_expr " "
 	and s_type_param tabs t =
 	and s_type_param tabs t =
-		t.tp_name ^ s_type_param_list tabs t.tp_params ^
+		fst (t.tp_name) ^ s_type_param_list tabs t.tp_params ^
 		if List.length t.tp_constraints > 0 then ":(" ^ String.concat ", " (List.map ((fun (t,_) -> s_complex_type tabs t)) 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 =
 	and s_type_param_list tabs tl =
 		if List.length tl > 0 then "<" ^ String.concat ", " (List.map (s_type_param tabs) tl) ^ ">" else ""
 		if List.length tl > 0 then "<" ^ String.concat ", " (List.map (s_type_param tabs) tl) ^ ">" else ""

+ 15 - 12
src/syntax/parser.ml

@@ -206,6 +206,9 @@ let reify in_macro =
 		else
 		else
 			(EConst (String s),p)
 			(EConst (String s),p)
 	in
 	in
+	let to_placed_name (s,p) =
+		to_string s p
+	in
 	let to_array f a p =
 	let to_array f a p =
 		(EArrayDecl (List.map (fun s -> f s p) a),p)
 		(EArrayDecl (List.map (fun s -> f s p) a),p)
 	in
 	in
@@ -266,7 +269,7 @@ let reify in_macro =
 		in
 		in
 		let rec fparam t p =
 		let rec fparam t p =
 			let fields = [
 			let fields = [
-				"name", to_string t.tp_name p;
+				"name", to_placed_name t.tp_name;
 				"constraints", to_array to_ctype t.tp_constraints p;
 				"constraints", to_array to_ctype t.tp_constraints p;
 				"params", to_array fparam t.tp_params p;
 				"params", to_array fparam t.tp_params p;
 			] in
 			] in
@@ -302,7 +305,7 @@ let reify in_macro =
 			mk_enum "FieldType" n vl p
 			mk_enum "FieldType" n vl p
 		in
 		in
 		let fields = [
 		let fields = [
-			Some ("name", to_string f.cff_name p);
+			Some ("name", to_placed_name f.cff_name);
 			(match f.cff_doc with None -> None | Some s -> Some ("doc", to_string s p));
 			(match f.cff_doc with None -> None | Some s -> Some ("doc", to_string s p));
 			(match f.cff_access with [] -> None | l -> Some ("access", to_array to_access l p));
 			(match f.cff_access with [] -> None | l -> Some ("access", to_array to_access l p));
 			Some ("kind", to_kind f.cff_kind);
 			Some ("kind", to_kind f.cff_kind);
@@ -467,7 +470,7 @@ let reify in_macro =
 				expr "EMeta" [to_obj [("name",to_string (fst (Common.MetaInfo.to_string m)) p);("params",to_expr_array ml p);("pos",to_pos p)] p;loop e1]
 				expr "EMeta" [to_obj [("name",to_string (fst (Common.MetaInfo.to_string m)) p);("params",to_expr_array ml p);("pos",to_pos p)] p;loop e1]
 	and to_tparam_decl p t =
 	and to_tparam_decl p t =
 		to_obj [
 		to_obj [
-			"name", to_string t.tp_name p;
+			"name", to_placed_name t.tp_name;
 			"params", (EArrayDecl (List.map (to_tparam_decl p) t.tp_params),p);
 			"params", (EArrayDecl (List.map (to_tparam_decl p) t.tp_params),p);
 			"constraints", (EArrayDecl (List.map (fun t -> to_ctype t p) t.tp_constraints),p)
 			"constraints", (EArrayDecl (List.map (fun t -> to_ctype t p) t.tp_constraints),p)
 		] p
 		] p
@@ -483,7 +486,7 @@ let reify in_macro =
 			) d.d_flags;
 			) d.d_flags;
 			to_obj [
 			to_obj [
 				"pack", (EArrayDecl [],p);
 				"pack", (EArrayDecl [],p);
-				"name", to_string d.d_name p;
+				"name", to_string (fst d.d_name) (pos d.d_name);
 				"pos", to_pos p;
 				"pos", to_pos p;
 				"meta", to_meta d.d_meta p;
 				"meta", to_meta d.d_meta p;
 				"params", (EArrayDecl (List.map (to_tparam_decl p) d.d_params),p);
 				"params", (EArrayDecl (List.map (to_tparam_decl p) d.d_params),p);
@@ -638,7 +641,7 @@ and parse_type_decl s =
 			},punion p1 p2)
 			},punion p1 p2)
 
 
 and parse_class doc meta cflags need_name s =
 and parse_class doc meta cflags need_name s =
-	let opt_name = if need_name then type_name else (fun s -> match popt type_name s with None -> "" | Some n -> n) in
+	let opt_name = if need_name then type_name else (fun s -> match popt type_name s with None -> "",null_pos | Some n -> n) in
 	match s with parser
 	match s with parser
 	| [< n , p1 = parse_class_flags; name = opt_name; tl = parse_constraint_params; hl = psep Comma parse_class_herit; '(BrOpen,_); fl, p2 = parse_class_fields (not need_name) p1 >] ->
 	| [< n , p1 = parse_class_flags; name = opt_name; tl = parse_constraint_params; hl = psep Comma parse_class_herit; '(BrOpen,_); fl, p2 = parse_class_fields (not need_name) p1 >] ->
 		(EClass {
 		(EClass {
@@ -899,8 +902,8 @@ and type_name = parser
 		if is_lower_ident name then
 		if is_lower_ident name then
 			error (Custom "Type name should start with an uppercase letter") p
 			error (Custom "Type name should start with an uppercase letter") p
 		else
 		else
-			name
-	| [< '(Dollar name,_) >] -> "$" ^ name
+			name,p
+	| [< '(Dollar name,p) >] -> "$" ^ name,p
 
 
 and parse_type_path_or_const = parser
 and parse_type_path_or_const = parser
 	(* we can't allow (expr) here *)
 	(* we can't allow (expr) here *)
@@ -924,7 +927,7 @@ and parse_type_anonymous opt = parser
 	| [< name, p1 = ident; t = parse_type_hint_with_pos; s >] ->
 	| [< name, p1 = ident; t = parse_type_hint_with_pos; s >] ->
 		let next p2 acc =
 		let next p2 acc =
 			{
 			{
-				cff_name = name;
+				cff_name = name,p1;
 				cff_meta = if opt then [Meta.Optional,[],p1] else [];
 				cff_meta = if opt then [Meta.Optional,[],p1] else [];
 				cff_access = [];
 				cff_access = [];
 				cff_doc = None;
 				cff_doc = None;
@@ -956,7 +959,7 @@ and parse_enum s =
 			| [< >] -> serror()
 			| [< >] -> serror()
 		) in
 		) in
 		{
 		{
-			ec_name = name;
+			ec_name = name,p1;
 			ec_doc = doc;
 			ec_doc = doc;
 			ec_meta = meta;
 			ec_meta = meta;
 			ec_args = args;
 			ec_args = args;
@@ -974,7 +977,7 @@ and parse_class_field s =
 	match s with parser
 	match s with parser
 	| [< meta = parse_meta; al = parse_cf_rights true []; s >] ->
 	| [< meta = parse_meta; al = parse_cf_rights true []; s >] ->
 		let name, pos, k = (match s with parser
 		let name, pos, k = (match s with parser
-		| [< '(Kwd Var,p1); name, _ = dollar_ident; s >] ->
+		| [< '(Kwd Var,p1); name = dollar_ident; s >] ->
 			(match s with parser
 			(match s with parser
 			| [< '(POpen,_); i1 = property_ident; '(Comma,_); i2 = property_ident; '(PClose,_) >] ->
 			| [< '(POpen,_); i1 = property_ident; '(Comma,_); i2 = property_ident; '(PClose,_) >] ->
 				let t = popt parse_type_hint_with_pos s in
 				let t = popt parse_type_hint_with_pos s in
@@ -1029,8 +1032,8 @@ and parse_cf_rights allow_static l = parser
 	| [< >] -> l
 	| [< >] -> l
 
 
 and parse_fun_name = parser
 and parse_fun_name = parser
-	| [< name,_ = dollar_ident >] -> name
-	| [< '(Kwd New,_) >] -> "new"
+	| [< name,p = dollar_ident >] -> name,p
+	| [< '(Kwd New,p) >] -> "new",p
 
 
 and parse_fun_param s =
 and parse_fun_param s =
 	let meta = parse_meta s in
 	let meta = parse_meta s in

+ 1 - 1
src/typing/type.ml

@@ -2392,7 +2392,7 @@ module TExprToExpr = struct
 			| _ ->
 			| _ ->
 				CTAnonymous (PMap.foldi (fun _ f acc ->
 				CTAnonymous (PMap.foldi (fun _ f acc ->
 					{
 					{
-						cff_name = f.cf_name;
+						cff_name = f.cf_name,null_pos;
 						cff_kind = FVar (mk_type_hint f.cf_type null_pos,None);
 						cff_kind = FVar (mk_type_hint f.cf_type null_pos,None);
 						cff_pos = f.cf_pos;
 						cff_pos = f.cf_pos;
 						cff_doc = f.cf_doc;
 						cff_doc = f.cf_doc;

+ 0 - 1
src/typing/typecore.ml

@@ -108,7 +108,6 @@ and typer = {
 	mutable untyped : bool;
 	mutable untyped : bool;
 	mutable in_loop : bool;
 	mutable in_loop : bool;
 	mutable in_display : bool;
 	mutable in_display : bool;
-	mutable display_handled : bool;
 	mutable in_macro : bool;
 	mutable in_macro : bool;
 	mutable macro_depth : int;
 	mutable macro_depth : int;
 	mutable curfun : current_fun;
 	mutable curfun : current_fun;

+ 90 - 89
src/typing/typeload.ml

@@ -36,7 +36,7 @@ let transform_abstract_field com this_t a_t a f =
 		{ f with cff_access = AStatic :: f.cff_access; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 		{ f with cff_access = AStatic :: f.cff_access; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 	| FProp _ when not stat ->
 	| FProp _ when not stat ->
 		error "Member property accessors must be get/set or never" p;
 		error "Member property accessors must be get/set or never" p;
-	| FFun fu when f.cff_name = "new" && not stat ->
+	| FFun fu when fst f.cff_name = "new" && not stat ->
 		let init p = (EVars [("this",null_pos),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 cast e = (ECast(e,None)),pos e in
 		let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
 		let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
@@ -58,7 +58,7 @@ let transform_abstract_field com this_t a_t a f =
 			f_type = Some a_t;
 			f_type = Some a_t;
 		} in
 		} in
 
 
-		{ f with cff_name = "_new"; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = meta }
+		{ f with cff_name = "_new",pos f.cff_name; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = meta }
 	| FFun fu when not stat ->
 	| FFun fu when not stat ->
 		if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
 		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",null_pos),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
@@ -94,10 +94,11 @@ let module_pass_1 ctx m tdecls loadp =
 			| None -> acc
 			| None -> acc
 			| Some _ -> error "import and using may not appear after a type declaration" p)
 			| Some _ -> error "import and using may not appear after a type declaration" p)
 		| EClass d ->
 		| EClass d ->
-			if String.length d.d_name > 0 && d.d_name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
+			let name = fst d.d_name in
+			if String.length name > 0 && name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
 			pt := Some p;
 			pt := Some p;
 			let priv = List.mem HPrivate d.d_flags in
 			let priv = List.mem HPrivate d.d_flags in
-			let path = make_path d.d_name priv in
+			let path = make_path name priv in
 			let c = mk_class m path p in
 			let c = mk_class m path p in
 			(* we shouldn't load any other type until we propertly set cl_build *)
 			(* we shouldn't load any other type until we propertly set cl_build *)
 			c.cl_build <- (fun() -> assert false);
 			c.cl_build <- (fun() -> assert false);
@@ -108,10 +109,11 @@ let module_pass_1 ctx m tdecls loadp =
 			decls := (TClassDecl c, decl) :: !decls;
 			decls := (TClassDecl c, decl) :: !decls;
 			acc
 			acc
 		| EEnum d ->
 		| EEnum d ->
-			if String.length d.d_name > 0 && d.d_name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
+			let name = fst d.d_name in
+			if String.length name > 0 && name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
 			pt := Some p;
 			pt := Some p;
 			let priv = List.mem EPrivate d.d_flags in
 			let priv = List.mem EPrivate d.d_flags in
-			let path = make_path d.d_name priv in
+			let path = make_path name priv in
 			let e = {
 			let e = {
 				e_path = path;
 				e_path = path;
 				e_module = m;
 				e_module = m;
@@ -137,10 +139,11 @@ let module_pass_1 ctx m tdecls loadp =
 			decls := (TEnumDecl e, decl) :: !decls;
 			decls := (TEnumDecl e, decl) :: !decls;
 			acc
 			acc
 		| ETypedef d ->
 		| ETypedef d ->
-			if String.length d.d_name > 0 && d.d_name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
+			let name = fst d.d_name in
+			if String.length name > 0 && name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
 			pt := Some p;
 			pt := Some p;
 			let priv = List.mem EPrivate d.d_flags in
 			let priv = List.mem EPrivate d.d_flags in
-			let path = make_path d.d_name priv in
+			let path = make_path name priv in
 			let t = {
 			let t = {
 				t_path = path;
 				t_path = path;
 				t_module = m;
 				t_module = m;
@@ -160,9 +163,10 @@ let module_pass_1 ctx m tdecls loadp =
 			decls := (TTypeDecl t, decl) :: !decls;
 			decls := (TTypeDecl t, decl) :: !decls;
 			acc
 			acc
 		 | EAbstract d ->
 		 | EAbstract d ->
-			if String.length d.d_name > 0 && d.d_name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
+		 	let name = fst d.d_name in
+			if String.length name > 0 && name.[0] = '$' then error "Type names starting with a dollar are not allowed" p;
 			let priv = List.mem APrivAbstract d.d_flags in
 			let priv = List.mem APrivAbstract d.d_flags in
-			let path = make_path d.d_name priv in
+			let path = make_path name priv in
 			let a = {
 			let a = {
 				a_path = path;
 				a_path = path;
 				a_private = priv;
 				a_private = priv;
@@ -189,8 +193,8 @@ let module_pass_1 ctx m tdecls loadp =
 				acc
 				acc
 			| fields ->
 			| fields ->
 				let a_t =
 				let a_t =
-					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
+					let params = List.map (fun t -> TPType (CTPath { tname = fst t.tp_name; tparams = []; tsub = None; tpackage = [] },null_pos)) d.d_params in
+					CTPath { tpackage = []; tname = fst d.d_name; tparams = params; tsub = None },null_pos
 				in
 				in
 				let rec loop = function
 				let rec loop = function
 					| [] -> a_t
 					| [] -> a_t
@@ -201,7 +205,7 @@ let module_pass_1 ctx m tdecls loadp =
 				let fields = List.map (transform_abstract_field com this_t a_t a) fields in
 				let fields = List.map (transform_abstract_field com this_t a_t a) fields in
 				let meta = ref [] in
 				let meta = ref [] in
 				if has_meta Meta.Dce a.a_meta then meta := (Meta.Dce,[],p) :: !meta;
 				if has_meta Meta.Dce a.a_meta then meta := (Meta.Dce,[],p) :: !meta;
-				let acc = make_decl acc (EClass { d_name = d.d_name ^ "_Impl_"; d_flags = [HPrivate]; d_data = fields; d_doc = None; d_params = []; d_meta = !meta },p) in
+				let acc = make_decl acc (EClass { d_name = (fst d.d_name) ^ "_Impl_",snd d.d_name; d_flags = [HPrivate]; d_data = fields; d_doc = None; d_params = []; d_meta = !meta },p) in
 				(match !decls with
 				(match !decls with
 				| (TClassDecl c,_) :: _ ->
 				| (TClassDecl c,_) :: _ ->
 					List.iter (fun m -> match m with
 					List.iter (fun m -> match m with
@@ -550,7 +554,7 @@ and load_complex_type ctx allow_display (t,p) =
 		| _ -> assert false)
 		| _ -> assert false)
 	| CTAnonymous l ->
 	| CTAnonymous l ->
 		let rec loop acc f =
 		let rec loop acc f =
-			let n = f.cff_name in
+			let n = fst f.cff_name in
 			let p = f.cff_pos in
 			let p = f.cff_pos in
 			if PMap.mem n acc then error ("Duplicate field declaration : " ^ n) p;
 			if PMap.mem n acc then error ("Duplicate field declaration : " ^ n) p;
 			let topt = function
 			let topt = function
@@ -579,7 +583,7 @@ and load_complex_type ctx allow_display (t,p) =
 					no_expr e;
 					no_expr e;
 					topt t, Var { v_read = AccNormal; v_write = AccNormal }
 					topt t, Var { v_read = AccNormal; v_write = AccNormal }
 				| FFun fd ->
 				| FFun fd ->
-					params := (!type_function_params_rec) ctx fd f.cff_name p;
+					params := (!type_function_params_rec) ctx fd (fst f.cff_name) p;
 					no_expr fd.f_expr;
 					no_expr fd.f_expr;
 					let old = ctx.type_params in
 					let old = ctx.type_params in
 					ctx.type_params <- !params @ old;
 					ctx.type_params <- !params @ old;
@@ -1496,7 +1500,7 @@ module Inheritance = struct
 end
 end
 
 
 let rec type_type_param ?(enum_constructor=false) ctx path get_params p tp =
 let rec type_type_param ?(enum_constructor=false) ctx path get_params p tp =
-	let n = tp.tp_name in
+	let n = fst tp.tp_name in
 	let c = mk_class ctx.m.curmod (fst path @ [snd path],n) p in
 	let c = mk_class ctx.m.curmod (fst path @ [snd path],n) p in
 	c.cl_params <- type_type_params ctx c.cl_path get_params p tp.tp_params;
 	c.cl_params <- type_type_params ctx c.cl_path get_params p tp.tp_params;
 	c.cl_kind <- KTypeParameter [];
 	c.cl_kind <- KTypeParameter [];
@@ -1530,8 +1534,8 @@ let rec type_type_param ?(enum_constructor=false) ctx path get_params p tp =
 and type_type_params ?(enum_constructor=false) ctx path get_params p tpl =
 and type_type_params ?(enum_constructor=false) ctx path get_params p tpl =
 	let names = ref [] in
 	let names = ref [] in
 	List.map (fun tp ->
 	List.map (fun tp ->
-		if List.mem tp.tp_name !names then display_error ctx ("Duplicate type parameter name: " ^ tp.tp_name) p;
-		names := tp.tp_name :: !names;
+		if List.exists (fun name -> name = fst tp.tp_name) !names then display_error ctx ("Duplicate type parameter name: " ^ fst tp.tp_name) p;
+		names := (fst tp.tp_name) :: !names;
 		type_type_param ~enum_constructor ctx path get_params p tp
 		type_type_param ~enum_constructor ctx path get_params p tp
 	) tpl
 	) tpl
 
 
@@ -1547,10 +1551,8 @@ let type_function ctx args ret fmode f do_display p =
 		let c = type_function_arg_value ctx t c in
 		let c = type_function_arg_value ctx t c in
 		let v,c = add_local ctx n t pn, c in
 		let v,c = add_local ctx n t pn, c in
 		v.v_meta <- m;
 		v.v_meta <- m;
-		if do_display && Display.encloses_position !Parser.resume_display pn then begin
-			ctx.display_handled <- true;
+		if do_display && Display.encloses_position !Parser.resume_display pn then
 			Display.display_variable ctx.com.display v;
 			Display.display_variable ctx.com.display v;
-		end;
 		if n = "this" then v.v_meta <- (Meta.This,[],p) :: v.v_meta;
 		if n = "this" then v.v_meta <- (Meta.This,[],p) :: v.v_meta;
 		v,c
 		v,c
 	) args f.f_args in
 	) args f.f_args in
@@ -1776,7 +1778,7 @@ let patch_class ctx c fields =
 				| FFun ff ->
 				| FFun ff ->
 					let param (((n,pn),opt,m,_,e) as p) =
 					let param (((n,pn),opt,m,_,e) as p) =
 						try
 						try
-							let t2 = (try Hashtbl.find h (("$" ^ f.cff_name ^ "__" ^ n),false) with Not_found -> Hashtbl.find h (("$" ^ n),false)) in
+							let t2 = (try Hashtbl.find h (("$" ^ (fst f.cff_name) ^ "__" ^ n),false) with Not_found -> Hashtbl.find h (("$" ^ n),false)) in
 							(n,pn), opt, m, (match t2.tp_type with None -> None | Some t -> Some (t,null_pos)), e
 							(n,pn), opt, m, (match t2.tp_type with None -> None | Some t -> Some (t,null_pos)), e
 						with Not_found ->
 						with Not_found ->
 							p
 							p
@@ -1784,7 +1786,7 @@ let patch_class ctx c fields =
 					f.cff_kind <- FFun { ff with f_args = List.map param ff.f_args }
 					f.cff_kind <- FFun { ff with f_args = List.map param ff.f_args }
 				| _ -> ());
 				| _ -> ());
 				(* other patches *)
 				(* other patches *)
-				match (try Some (Hashtbl.find h (f.cff_name,List.mem AStatic f.cff_access)) with Not_found -> None) with
+				match (try Some (Hashtbl.find h (fst f.cff_name,List.mem AStatic f.cff_access)) with Not_found -> None) with
 				| None -> loop (f :: acc) l
 				| None -> loop (f :: acc) l
 				| Some { tp_remove = true } -> loop acc l
 				| Some { tp_remove = true } -> loop acc l
 				| Some p ->
 				| Some p ->
@@ -1978,7 +1980,7 @@ module ClassInitializer = struct
 		let is_inline = allow_inline && List.mem AInline cff.cff_access in
 		let is_inline = allow_inline && List.mem AInline cff.cff_access in
 		let is_override = List.mem AOverride cff.cff_access in
 		let is_override = List.mem AOverride cff.cff_access in
 		let is_macro = List.mem AMacro cff.cff_access in
 		let is_macro = List.mem AMacro cff.cff_access in
-		let field_kind = match cff.cff_name with
+		let field_kind = match fst cff.cff_name with
 			| "new" -> FKConstructor
 			| "new" -> FKConstructor
 			| "__init__" when is_static -> FKInit
 			| "__init__" when is_static -> FKInit
 			| _ -> FKNormal
 			| _ -> FKNormal
@@ -2103,17 +2105,6 @@ module ClassInitializer = struct
 				end;
 				end;
 			end
 			end
 
 
-	let check_display (ctx,fctx) cf p =
-		if fctx.is_display_field && not ctx.display_handled then begin
-			(* We're in our display field but didn't exit yet, so the position must be on the field itself.
-			   It could also be one of its arguments, but at the moment we cannot detect that. *)
-		match ctx.com.display with
-			| DMPosition -> raise (Display.DisplayPosition [cf.cf_pos]);
-			| DMUsage -> cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
-			| DMType -> raise (Display.DisplayTypes [cf.cf_type])
-			| _ -> ()
-		end
-
 	let bind_var (ctx,cctx,fctx) cf e =
 	let bind_var (ctx,cctx,fctx) cf e =
 		let c = cctx.tclass in
 		let c = cctx.tclass in
 		let p = cf.cf_pos in
 		let p = cf.cf_pos in
@@ -2145,7 +2136,7 @@ module ClassInitializer = struct
 
 
 		match e with
 		match e with
 		| None ->
 		| None ->
-			check_display (ctx,fctx) cf p
+			()
 		| Some e ->
 		| Some e ->
 			if requires_value_meta ctx.com (Some c) then cf.cf_meta <- ((Meta.Value,[e],cf.cf_pos) :: cf.cf_meta);
 			if requires_value_meta ctx.com (Some c) then cf.cf_meta <- ((Meta.Value,[e],cf.cf_pos) :: cf.cf_meta);
 			let check_cast e =
 			let check_cast e =
@@ -2223,7 +2214,6 @@ module ClassInitializer = struct
 						e
 						e
 					) in
 					) in
 					let e = check_cast e in
 					let e = check_cast e in
-					check_display (ctx,fctx) cf p;
 					cf.cf_expr <- Some e;
 					cf.cf_expr <- Some e;
 					cf.cf_type <- t;
 					cf.cf_type <- t;
 				end;
 				end;
@@ -2232,14 +2222,18 @@ module ClassInitializer = struct
 			if not fctx.is_static then cctx.force_constructor <- true;
 			if not fctx.is_static then cctx.force_constructor <- true;
 			bind_type (ctx,cctx,fctx) cf r (snd e)
 			bind_type (ctx,cctx,fctx) cf r (snd e)
 
 
+	let check_field_display com p cf =
+ 		if Display.encloses_position !Parser.resume_display p then
+			Display.display_field com.display cf
+
 	let create_variable (ctx,cctx,fctx) c f t eo p =
 	let create_variable (ctx,cctx,fctx) c f t eo p =
-		if not fctx.is_static && cctx.abstract <> None then error (f.cff_name ^ ": Cannot declare member variable in abstract") p;
-		if fctx.is_inline && not fctx.is_static then error (f.cff_name ^ ": Inline variable must be static") p;
-		if fctx.is_inline && eo = None then error (f.cff_name ^ ": Inline variable must be initialized") p;
+		if not fctx.is_static && cctx.abstract <> None then error (fst f.cff_name ^ ": Cannot declare member variable in abstract") p;
+		if fctx.is_inline && not fctx.is_static then error (fst f.cff_name ^ ": Inline variable must be static") p;
+		if fctx.is_inline && eo = None then error (fst f.cff_name ^ ": Inline variable must be initialized") p;
 
 
 		let t = (match t with
 		let t = (match t with
 			| None when not fctx.is_static && eo = None ->
 			| None when not fctx.is_static && eo = None ->
-				error ("Type required for member variable " ^ f.cff_name) p;
+				error ("Type required for member variable " ^ fst f.cff_name) p;
 			| None ->
 			| None ->
 				mk_mono()
 				mk_mono()
 			| Some t ->
 			| Some t ->
@@ -2251,7 +2245,7 @@ module ClassInitializer = struct
 				t
 				t
 		) in
 		) in
 		let cf = {
 		let cf = {
-			cf_name = f.cff_name;
+			cf_name = fst f.cff_name;
 			cf_doc = f.cff_doc;
 			cf_doc = f.cff_doc;
 			cf_meta = f.cff_meta;
 			cf_meta = f.cff_meta;
 			cf_type = t;
 			cf_type = t;
@@ -2264,6 +2258,7 @@ module ClassInitializer = struct
 		} in
 		} in
 		ctx.curfield <- cf;
 		ctx.curfield <- cf;
 		bind_var (ctx,cctx,fctx) cf eo;
 		bind_var (ctx,cctx,fctx) cf eo;
+		if fctx.is_display_field then check_field_display ctx.com (pos f.cff_name) cf;
 		cf
 		cf
 
 
 	let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 	let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
@@ -2385,9 +2380,9 @@ module ClassInitializer = struct
 				()
 				()
 
 
 	let create_method (ctx,cctx,fctx) c f fd p =
 	let create_method (ctx,cctx,fctx) c f fd p =
-		let params = type_function_params ctx fd f.cff_name p in
+		let params = type_function_params ctx fd (fst f.cff_name) p in
 		if Meta.has Meta.Generic f.cff_meta then begin
 		if Meta.has Meta.Generic f.cff_meta then begin
-			if params = [] then error (f.cff_name ^ ": Generic functions must have type parameters") p;
+			if params = [] then error (fst f.cff_name ^ ": Generic functions must have type parameters") p;
 		end;
 		end;
 		let fd = if fctx.is_macro && not ctx.in_macro && not fctx.is_static then
 		let fd = if fctx.is_macro && not ctx.in_macro && not fctx.is_static then
 			(* remove display of first argument which will contain the "this" expression *)
 			(* remove display of first argument which will contain the "this" expression *)
@@ -2433,8 +2428,8 @@ module ClassInitializer = struct
 			| true,FKConstructor ->
 			| true,FKConstructor ->
 				error "An interface cannot have a constructor" p;
 				error "An interface cannot have a constructor" p;
 			| true,_ ->
 			| true,_ ->
-				if not fctx.is_static && fd.f_expr <> None then error (f.cff_name ^ ": An interface method cannot have a body") p;
-				if fctx.is_inline && c.cl_interface then error (f.cff_name ^ ": You can't declare inline methods in interfaces") p;
+				if not fctx.is_static && fd.f_expr <> None then error (fst f.cff_name ^ ": An interface method cannot have a body") p;
+				if fctx.is_inline && c.cl_interface then error (fst f.cff_name ^ ": You can't declare inline methods in interfaces") p;
 			| false,FKConstructor ->
 			| false,FKConstructor ->
 				if fctx.is_static then error "A constructor must not be static" p;
 				if fctx.is_static then error "A constructor must not be static" p;
 				begin match fd.f_type with
 				begin match fd.f_type with
@@ -2444,9 +2439,9 @@ module ClassInitializer = struct
 			| false,_ ->
 			| false,_ ->
 				()
 				()
 		end;
 		end;
-		let parent = (if not fctx.is_static then get_parent c f.cff_name else None) in
+		let parent = (if not fctx.is_static then get_parent c (fst f.cff_name) else None) in
 		let dynamic = List.mem ADynamic f.cff_access || (match parent with Some { cf_kind = Method MethDynamic } -> true | _ -> false) in
 		let dynamic = List.mem ADynamic f.cff_access || (match parent with Some { cf_kind = Method MethDynamic } -> true | _ -> false) in
-		if fctx.is_inline && dynamic then error (f.cff_name ^ ": You can't have both 'inline' and 'dynamic'") p;
+		if fctx.is_inline && dynamic then error (fst f.cff_name ^ ": You can't have both 'inline' and 'dynamic'") p;
 		ctx.type_params <- (match cctx.abstract with
 		ctx.type_params <- (match cctx.abstract with
 			| Some a when fctx.is_abstract_member ->
 			| Some a when fctx.is_abstract_member ->
 				params @ a.a_params
 				params @ a.a_params
@@ -2474,7 +2469,7 @@ module ClassInitializer = struct
 		let args = loop fd.f_args in
 		let args = loop fd.f_args in
 		let t = TFun (fun_args args,ret) in
 		let t = TFun (fun_args args,ret) in
 		let cf = {
 		let cf = {
-			cf_name = f.cff_name;
+			cf_name = fst f.cff_name;
 			cf_doc = f.cff_doc;
 			cf_doc = f.cff_doc;
 			cf_meta = f.cff_meta;
 			cf_meta = f.cff_meta;
 			cf_type = t;
 			cf_type = t;
@@ -2498,12 +2493,12 @@ module ClassInitializer = struct
 				r := (fun() -> t);
 				r := (fun() -> t);
 				cctx.context_init();
 				cctx.context_init();
 				incr stats.s_methods_typed;
 				incr stats.s_methods_typed;
-				if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ f.cff_name);
+				if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ fst f.cff_name);
 				let fmode = (match cctx.abstract with
 				let fmode = (match cctx.abstract with
 					| Some _ ->
 					| Some _ ->
 						(match args with
 						(match args with
 						| ("this",_,_) :: _ -> FunMemberAbstract
 						| ("this",_,_) :: _ -> FunMemberAbstract
-						| _ when f.cff_name = "_new" -> FunMemberAbstract
+						| _ when fst f.cff_name = "_new" -> FunMemberAbstract
 						| _ -> FunStatic)
 						| _ -> FunStatic)
 					| None ->
 					| None ->
 						if fctx.field_kind = FKConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
 						if fctx.field_kind = FKConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
@@ -2516,7 +2511,6 @@ module ClassInitializer = struct
 						cf.cf_type <- t
 						cf.cf_type <- t
 					| _ ->
 					| _ ->
 						let e , fargs = type_function ctx args ret fmode fd fctx.is_display_field p in
 						let e , fargs = type_function ctx args ret fmode fd fctx.is_display_field p in
-						check_display (ctx,fctx) cf p;
 						let tf = {
 						let tf = {
 							tf_args = fargs;
 							tf_args = fargs;
 							tf_type = ret;
 							tf_type = ret;
@@ -2532,22 +2526,24 @@ module ClassInitializer = struct
 			t
 			t
 		) "type_fun" in
 		) "type_fun" in
 		if fctx.do_bind then bind_type (ctx,cctx,fctx) cf r (match fd.f_expr with Some e -> snd e | None -> f.cff_pos);
 		if fctx.do_bind then bind_type (ctx,cctx,fctx) cf r (match fd.f_expr with Some e -> snd e | None -> f.cff_pos);
+		if fctx.is_display_field then check_field_display ctx.com (pos f.cff_name) cf;
 		cf
 		cf
 
 
 	let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 	let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
+		let name = fst f.cff_name in
 		(match cctx.abstract with
 		(match cctx.abstract with
 		| Some a when fctx.is_abstract_member ->
 		| Some a when fctx.is_abstract_member ->
 			ctx.type_params <- a.a_params;
 			ctx.type_params <- a.a_params;
 		| _ -> ());
 		| _ -> ());
 		(* TODO is_lib: lazify load_complex_type *)
 		(* TODO is_lib: lazify load_complex_type *)
 		let ret = (match t, eo with
 		let ret = (match t, eo with
-			| None, None -> error (f.cff_name ^ ": Property must either define a type or a default value") p;
+			| None, None -> error (name ^ ": Property must either define a type or a default value") p;
 			| None, _ -> mk_mono()
 			| None, _ -> mk_mono()
 			| Some t, _ -> load_complex_type ctx true t
 			| Some t, _ -> load_complex_type ctx true t
 		) in
 		) in
 		let t_get,t_set = match cctx.abstract with
 		let t_get,t_set = match cctx.abstract with
 			| Some a when fctx.is_abstract_member ->
 			| Some a when fctx.is_abstract_member ->
-				if Meta.has Meta.IsVar f.cff_meta then error (f.cff_name ^ ": Abstract properties cannot be real variables") f.cff_pos;
+				if Meta.has Meta.IsVar f.cff_meta then error (name ^ ": Abstract properties cannot be real variables") f.cff_pos;
 				let ta = apply_params a.a_params (List.map snd a.a_params) a.a_this in
 				let ta = apply_params a.a_params (List.map snd a.a_params) a.a_this in
 				tfun [ta] ret, tfun [ta;ret] ret
 				tfun [ta] ret, tfun [ta;ret] ret
 			| _ -> tfun [] ret, TFun(["value",false,ret],ret)
 			| _ -> tfun [] ret, TFun(["value",false,ret],ret)
@@ -2583,7 +2579,7 @@ module ClassInitializer = struct
 							raise Not_found
 							raise Not_found
 						else
 						else
 							raise (Error (Custom
 							raise (Error (Custom
-								(Printf.sprintf "No overloaded method named %s was compatible with the property %s with expected type %s" m f.cff_name (s_type (print_context()) t)
+								(Printf.sprintf "No overloaded method named %s was compatible with the property %s with expected type %s" m (name) (s_type (print_context()) t)
 							), p))
 							), p))
 				in
 				in
 				let t2, f2 = get_overload overloads in
 				let t2, f2 = get_overload overloads in
@@ -2603,9 +2599,9 @@ module ClassInitializer = struct
 					| _ -> acc
 					| _ -> acc
 				) f2.cf_meta f.cff_meta;
 				) f2.cf_meta f.cff_meta;
 			with
 			with
-				| Error (Unify l,p) -> raise (Error (Stack (Custom ("In method " ^ m ^ " required by property " ^ f.cff_name),Unify l),p))
+				| Error (Unify l,p) -> raise (Error (Stack (Custom ("In method " ^ m ^ " required by property " ^ name),Unify l),p))
 				| Not_found ->
 				| Not_found ->
-					if req_name <> None then display_error ctx (f.cff_name ^ ": Custom property accessor is no longer supported, please use get/set") p else
+					if req_name <> None then display_error ctx (name ^ ": Custom property accessor is no longer supported, please use get/set") p else
 					if c.cl_interface then begin
 					if c.cl_interface then begin
 						let cf = mk_field m t p in
 						let cf = mk_field m t p in
 						cf.cf_meta <- [Meta.CompilerGenerated,[],p];
 						cf.cf_meta <- [Meta.CompilerGenerated,[],p];
@@ -2615,9 +2611,9 @@ module ClassInitializer = struct
 					end else if not c.cl_extern then begin
 					end else if not c.cl_extern then begin
 						try
 						try
 							let _, _, f2 = (if not fctx.is_static then let f = PMap.find m c.cl_statics in None, f.cf_type, f else class_field c (List.map snd c.cl_params) m) in
 							let _, _, f2 = (if not fctx.is_static then let f = PMap.find m c.cl_statics in None, f.cf_type, f else class_field c (List.map snd c.cl_params) m) in
-							display_error ctx (Printf.sprintf "Method %s is no valid accessor for %s because it is %sstatic" m f.cff_name (if fctx.is_static then "not " else "")) f2.cf_pos
+							display_error ctx (Printf.sprintf "Method %s is no valid accessor for %s because it is %sstatic" m (name) (if fctx.is_static then "not " else "")) f2.cf_pos
 						with Not_found ->
 						with Not_found ->
-							display_error ctx ("Method " ^ m ^ " required by property " ^ f.cff_name ^ " is missing") p
+							display_error ctx ("Method " ^ m ^ " required by property " ^ name ^ " is missing") p
 					end
 					end
 		in
 		in
 		let get = (match get with
 		let get = (match get with
@@ -2626,8 +2622,8 @@ module ClassInitializer = struct
 			| "never" -> AccNever
 			| "never" -> AccNever
 			| "default" -> AccNormal
 			| "default" -> AccNormal
 			| _ ->
 			| _ ->
-				let get = if get = "get" then "get_" ^ f.cff_name else get in
-				if not cctx.is_lib then delay ctx PTypeField (fun() -> check_method get t_get (if get <> "get" && get <> "get_" ^ f.cff_name then Some ("get_" ^ f.cff_name) else None));
+				let get = if get = "get" then "get_" ^ name else get in
+				if not cctx.is_lib then delay ctx PTypeField (fun() -> check_method get t_get (if get <> "get" && get <> "get_" ^ name then Some ("get_" ^ name) else None));
 				AccCall
 				AccCall
 		) in
 		) in
 		let set = (match set with
 		let set = (match set with
@@ -2641,13 +2637,13 @@ module ClassInitializer = struct
 			| "dynamic" -> AccCall
 			| "dynamic" -> AccCall
 			| "default" -> AccNormal
 			| "default" -> AccNormal
 			| _ ->
 			| _ ->
-				let set = if set = "set" then "set_" ^ f.cff_name else set in
-				if not cctx.is_lib then delay ctx PTypeField (fun() -> check_method set t_set (if set <> "set" && set <> "set_" ^ f.cff_name then Some ("set_" ^ f.cff_name) else None));
+				let set = if set = "set" then "set_" ^ name else set in
+				if not cctx.is_lib then delay ctx PTypeField (fun() -> check_method set t_set (if set <> "set" && set <> "set_" ^ name then Some ("set_" ^ name) else None));
 				AccCall
 				AccCall
 		) in
 		) in
-		if set = AccNormal && (match get with AccCall -> true | _ -> false) then error (f.cff_name ^ ": Unsupported property combination") p;
+		if set = AccNormal && (match get with AccCall -> true | _ -> false) then error (name ^ ": Unsupported property combination") p;
 		let cf = {
 		let cf = {
-			cf_name = f.cff_name;
+			cf_name = name;
 			cf_doc = f.cff_doc;
 			cf_doc = f.cff_doc;
 			cf_meta = f.cff_meta;
 			cf_meta = f.cff_meta;
 			cf_pos = f.cff_pos;
 			cf_pos = f.cff_pos;
@@ -2660,21 +2656,23 @@ module ClassInitializer = struct
 		} in
 		} in
 		ctx.curfield <- cf;
 		ctx.curfield <- cf;
 		bind_var (ctx,cctx,fctx) cf eo;
 		bind_var (ctx,cctx,fctx) cf eo;
+		if fctx.is_display_field then check_field_display ctx.com (pos f.cff_name) cf;
 		cf
 		cf
 
 
 	let init_field (ctx,cctx,fctx) f =
 	let init_field (ctx,cctx,fctx) f =
 		let c = cctx.tclass in
 		let c = cctx.tclass in
-		check_global_metadata ctx (fun m -> f.cff_meta <- m :: f.cff_meta) c.cl_module.m_path c.cl_path (Some f.cff_name);
+		let name = fst f.cff_name in
+		check_global_metadata ctx (fun m -> f.cff_meta <- m :: f.cff_meta) c.cl_module.m_path c.cl_path (Some name);
 		let p = f.cff_pos in
 		let p = f.cff_pos in
-		if f.cff_name.[0] = '$' && ctx.com.display = DMNone then error "Field names starting with a dollar are not allowed" p;
+		if name.[0] = '$' && ctx.com.display = DMNone then error "Field names starting with a dollar are not allowed" p;
 		List.iter (fun acc ->
 		List.iter (fun acc ->
 			match (acc, f.cff_kind) with
 			match (acc, f.cff_kind) with
 			| APublic, _ | APrivate, _ | AStatic, _ -> ()
 			| APublic, _ | APrivate, _ | AStatic, _ -> ()
 			| ADynamic, FFun _ | AOverride, FFun _ | AMacro, FFun _ | AInline, FFun _ | AInline, FVar _ -> ()
 			| ADynamic, FFun _ | AOverride, FFun _ | AMacro, FFun _ | AInline, FFun _ | AInline, FVar _ -> ()
-			| _, FVar _ -> error ("Invalid accessor '" ^ Ast.s_access acc ^ "' for variable " ^ f.cff_name) p
-			| _, FProp _ -> error ("Invalid accessor '" ^ Ast.s_access acc ^ "' for property " ^ f.cff_name) p
+			| _, FVar _ -> error ("Invalid accessor '" ^ Ast.s_access acc ^ "' for variable " ^ name) p
+			| _, FProp _ -> error ("Invalid accessor '" ^ Ast.s_access acc ^ "' for property " ^ name) p
 		) f.cff_access;
 		) f.cff_access;
-		if fctx.is_override then (match c.cl_super with None -> error ("Invalid override on field '" ^ f.cff_name ^ "': class has no super class") p | _ -> ());
+		if fctx.is_override then (match c.cl_super with None -> error ("Invalid override on field '" ^ name ^ "': class has no super class") p | _ -> ());
 		match f.cff_kind with
 		match f.cff_kind with
 		| FVar (t,e) ->
 		| FVar (t,e) ->
 			create_variable (ctx,cctx,fctx) c f t e p
 			create_variable (ctx,cctx,fctx) c f t e p
@@ -2989,7 +2987,8 @@ let init_module_type ctx context_init do_init (decl,p) =
 		in
 		in
 		context_init := (fun() -> ctx.m.module_using <- filter_classes types @ ctx.m.module_using) :: !context_init
 		context_init := (fun() -> ctx.m.module_using <- filter_classes types @ ctx.m.module_using) :: !context_init
 	| EClass d ->
 	| EClass d ->
-		let c = (match get_type d.d_name with TClassDecl c -> c | _ -> assert false) in
+		let c = (match get_type (fst d.d_name) with TClassDecl c -> c | _ -> assert false) in
+		if Display.is_display_position (pos d.d_name) then Display.display_module_type ctx.com.display (TClassDecl c);
 		check_global_metadata ctx (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None;
 		check_global_metadata ctx (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None;
 		let herits = d.d_flags in
 		let herits = d.d_flags in
 		if Meta.has Meta.Generic c.cl_meta && c.cl_params <> [] then c.cl_kind <- KGeneric;
 		if Meta.has Meta.Generic c.cl_meta && c.cl_params <> [] then c.cl_kind <- KGeneric;
@@ -3048,7 +3047,8 @@ let init_module_type ctx context_init do_init (decl,p) =
 					| _ -> ()
 					| _ -> ()
 			);
 			);
 	| EEnum d ->
 	| EEnum d ->
-		let e = (match get_type d.d_name with TEnumDecl e -> e | _ -> assert false) in
+		let e = (match get_type (fst d.d_name) with TEnumDecl e -> e | _ -> assert false) in
+		if Display.is_display_position (pos d.d_name) then Display.display_module_type ctx.com.display (TEnumDecl e);
 		let ctx = { ctx with type_params = e.e_params } in
 		let ctx = { ctx with type_params = e.e_params } in
 		let h = (try Some (Hashtbl.find ctx.g.type_patches e.e_path) with Not_found -> None) in
 		let h = (try Some (Hashtbl.find ctx.g.type_patches e.e_path) with Not_found -> None) in
 		check_global_metadata ctx (fun m -> e.e_meta <- m :: e.e_meta) e.e_module.m_path e.e_path None;
 		check_global_metadata ctx (fun m -> e.e_meta <- m :: e.e_meta) e.e_module.m_path e.e_path None;
@@ -3106,7 +3106,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 		List.iter (fun c ->
 		List.iter (fun c ->
 			let p = c.ec_pos in
 			let p = c.ec_pos in
 			let params = ref [] in
 			let params = ref [] in
-			params := type_type_params ~enum_constructor:true ctx ([],c.ec_name) (fun() -> !params) c.ec_pos c.ec_params;
+			params := type_type_params ~enum_constructor:true ctx ([],fst c.ec_name) (fun() -> !params) c.ec_pos c.ec_params;
 			let params = !params in
 			let params = !params in
 			let ctx = { ctx with type_params = params @ ctx.type_params } in
 			let ctx = { ctx with type_params = params @ ctx.type_params } in
 			let rt = (match c.ec_type with
 			let rt = (match c.ec_type with
@@ -3127,14 +3127,14 @@ let init_module_type ctx context_init do_init (decl,p) =
 					let pnames = ref PMap.empty in
 					let pnames = ref PMap.empty in
 					TFun (List.map (fun (s,opt,(t,tp)) ->
 					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 | _ -> ());
 						(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;
+						if PMap.mem s (!pnames) then error ("Duplicate parameter '" ^ s ^ "' in enum constructor " ^ fst c.ec_name) p;
 						pnames := PMap.add s () (!pnames);
 						pnames := PMap.add s () (!pnames);
 						s, opt, load_type_hint ~opt ctx (Some (t,tp))
 						s, opt, load_type_hint ~opt ctx (Some (t,tp))
 					) l, rt)
 					) l, rt)
 			) in
 			) in
-			if PMap.mem c.ec_name e.e_constrs then error ("Duplicate constructor " ^ c.ec_name) p;
+			if PMap.mem (fst c.ec_name) e.e_constrs then error ("Duplicate constructor " ^ fst c.ec_name) p;
 			let f = {
 			let f = {
-				ef_name = c.ec_name;
+				ef_name = fst c.ec_name;
 				ef_type = t;
 				ef_type = t;
 				ef_pos = p;
 				ef_pos = p;
 				ef_doc = c.ec_doc;
 				ef_doc = c.ec_doc;
@@ -3166,7 +3166,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 			e.e_constrs <- PMap.add f.ef_name f e.e_constrs;
 			e.e_constrs <- PMap.add f.ef_name f e.e_constrs;
 			fields := PMap.add cf.cf_name cf !fields;
 			fields := PMap.add cf.cf_name cf !fields;
 			incr index;
 			incr index;
-			names := c.ec_name :: !names;
+			names := (fst c.ec_name) :: !names;
 		) (!constructs);
 		) (!constructs);
 		e.e_names <- List.rev !names;
 		e.e_names <- List.rev !names;
 		e.e_extern <- e.e_extern;
 		e.e_extern <- e.e_extern;
@@ -3187,7 +3187,8 @@ let init_module_type ctx context_init do_init (decl,p) =
 				) e.e_constrs
 				) e.e_constrs
 			);
 			);
 	| ETypedef d ->
 	| ETypedef d ->
-		let t = (match get_type d.d_name with TTypeDecl t -> t | _ -> assert false) in
+		let t = (match get_type (fst d.d_name) with TTypeDecl t -> t | _ -> assert false) in
+		if Display.is_display_position (pos d.d_name) then Display.display_module_type ctx.com.display (TTypeDecl t);
 		check_global_metadata ctx (fun m -> t.t_meta <- m :: t.t_meta) t.t_module.m_path t.t_path None;
 		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 ctx = { ctx with type_params = t.t_params } in
 		let tt = load_complex_type ctx true d.d_data in
 		let tt = load_complex_type ctx true d.d_data in
@@ -3216,7 +3217,8 @@ let init_module_type ctx context_init do_init (decl,p) =
 				if metas <> [] then t.t_meta <- metas @ t.t_meta;
 				if metas <> [] then t.t_meta <- metas @ t.t_meta;
 			);
 			);
 	| EAbstract d ->
 	| EAbstract d ->
-		let a = (match get_type d.d_name with TAbstractDecl a -> a | _ -> assert false) in
+		let a = (match get_type (fst d.d_name) with TAbstractDecl a -> a | _ -> assert false) in
+		if Display.is_display_position (pos d.d_name) then Display.display_module_type ctx.com.display (TAbstractDecl a);
 		check_global_metadata ctx (fun m -> a.a_meta <- m :: a.a_meta) a.a_module.m_path a.a_path None;
 		check_global_metadata ctx (fun m -> a.a_meta <- m :: a.a_meta) a.a_module.m_path a.a_path None;
 		let ctx = { ctx with type_params = a.a_params } in
 		let ctx = { ctx with type_params = a.a_params } in
 		let is_type = ref false in
 		let is_type = ref false in
@@ -3330,7 +3332,6 @@ let type_types_into_module ctx m tdecls p =
 		untyped = false;
 		untyped = false;
 		in_macro = ctx.in_macro;
 		in_macro = ctx.in_macro;
 		in_display = false;
 		in_display = false;
-		display_handled = false;
 		in_loop = false;
 		in_loop = false;
 		opened = [];
 		opened = [];
 		in_call_args = false;
 		in_call_args = false;
@@ -3462,9 +3463,9 @@ let parse_module ctx m p =
 					d_data = CTPath (if priv then { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; } else
 					d_data = CTPath (if priv then { tpackage = []; tname = "Dynamic"; tparams = []; tsub = None; } else
 						{
 						{
 							tpackage = !remap;
 							tpackage = !remap;
-							tname = d.d_name;
+							tname = fst d.d_name;
 							tparams = List.map (fun tp ->
 							tparams = List.map (fun tp ->
-								TPType (CTPath { tpackage = []; tname = tp.tp_name; tparams = []; tsub = None; },null_pos)
+								TPType (CTPath { tpackage = []; tname = fst tp.tp_name; tparams = []; tsub = None; },null_pos)
 							) d.d_params;
 							) d.d_params;
 							tsub = None;
 							tsub = None;
 						}),null_pos;
 						}),null_pos;
@@ -3543,16 +3544,16 @@ let extend_remoting ctx c t p async prot =
 		| e -> ctx.com.package_rules <- rules; raise e) in
 		| e -> ctx.com.package_rules <- rules; raise e) in
 	ctx.com.package_rules <- rules;
 	ctx.com.package_rules <- rules;
 	let base_fields = [
 	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 },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 = [] } };
+		{ cff_name = "__cnx",null_pos; 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",null_pos; 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
 	] in
 	let tvoid = CTPath { tpackage = []; tname = "Void"; tparams = []; tsub = None } in
 	let tvoid = CTPath { tpackage = []; tname = "Void"; tparams = []; tsub = None } in
 	let build_field is_public acc f =
 	let build_field is_public acc f =
-		if f.cff_name = "new" then
+		if fst f.cff_name = "new" then
 			acc
 			acc
 		else match f.cff_kind with
 		else match f.cff_kind with
 		| FFun fd when (is_public || List.mem APublic f.cff_access) && not (List.mem AStatic f.cff_access) ->
 		| 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;
+			if List.exists (fun (_,_,_,t,_) -> t = None) fd.f_args then error ("Field " ^ fst 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 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 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
 			let fargs, eargs = if async then match ftype with
@@ -3561,7 +3562,7 @@ let extend_remoting ctx c t p async prot =
 			else
 			else
 				fd.f_args, eargs
 				fd.f_args, eargs
 			in
 			in
-			let id = (EConst (String f.cff_name), p) in
+			let id = (EConst (String (fst f.cff_name)), p) in
 			let id = if prot then id else ECall ((EConst (Ident "__unprotect__"),p),[id]),p in
 			let id = if prot then id else ECall ((EConst (Ident "__unprotect__"),p),[id]),p in
 			let expr = ECall (
 			let expr = ECall (
 				(EField (
 				(EField (
@@ -3581,10 +3582,10 @@ let extend_remoting ctx c t p async prot =
 	in
 	in
 	let decls = List.map (fun d ->
 	let decls = List.map (fun d ->
 		match d with
 		match d with
-		| EClass c, p when c.d_name = t.tname ->
+		| EClass c, p when fst c.d_name = t.tname ->
 			let is_public = List.mem HExtern c.d_flags || List.mem HInterface c.d_flags in
 			let is_public = List.mem HExtern c.d_flags || List.mem HInterface c.d_flags in
 			let fields = List.rev (List.fold_left (build_field is_public) base_fields c.d_data) in
 			let fields = List.rev (List.fold_left (build_field is_public) base_fields c.d_data) in
-			(EClass { c with d_flags = []; d_name = new_name; d_data = fields },p)
+			(EClass { c with d_flags = []; d_name = new_name,pos c.d_name; d_data = fields },p)
 		| _ -> d
 		| _ -> d
 	) decls in
 	) decls in
 	let m = type_module ctx (t.tpackage,new_name) file decls p in
 	let m = type_module ctx (t.tpackage,new_name) file decls p in

+ 25 - 14
src/typing/typer.ml

@@ -354,16 +354,16 @@ let eval ctx s =
 	let pack,decls = parse_string ctx.com s p false in
 	let pack,decls = parse_string ctx.com s p false in
 	let rec find_main current decls = match decls with
 	let rec find_main current decls = match decls with
 		| (EClass c,_) :: decls ->
 		| (EClass c,_) :: decls ->
-			let path = pack,c.d_name in
+			let path = pack,fst c.d_name in
 			begin try
 			begin try
-				let cff = List.find (fun cff -> cff.cff_name = "main") c.d_data in
+				let cff = List.find (fun cff -> fst cff.cff_name = "main") c.d_data in
 				if ctx.com.main_class <> None then error "Multiple main" cff.cff_pos;
 				if ctx.com.main_class <> None then error "Multiple main" cff.cff_pos;
 				ctx.com.main_class <- Some path;
 				ctx.com.main_class <- Some path;
 				Some path
 				Some path
 			with Not_found ->
 			with Not_found ->
 				find_main (if current = None then Some path else current) decls
 				find_main (if current = None then Some path else current) decls
 			end
 			end
-		| ((EEnum {d_name = s} | ETypedef {d_name = s} | EAbstract {d_name = s}),_) :: decls when current = None ->
+		| ((EEnum {d_name = (s,_)} | ETypedef {d_name = (s,_)} | EAbstract {d_name = (s,_)}),_) :: decls when current = None ->
 			find_main (Some (pack,s)) decls
 			find_main (Some (pack,s)) decls
 		| _ :: decls ->
 		| _ :: decls ->
 			find_main current decls
 			find_main current decls
@@ -382,7 +382,7 @@ let parse_expr_string ctx s p inl =
 	let head = (if p.pmin > String.length head then head ^ String.make (p.pmin - String.length head) ' ' else head) in
 	let head = (if p.pmin > String.length head then head ^ String.make (p.pmin - String.length head) ' ' else head) in
 	let rec loop e = let e = Ast.map_expr loop e in (fst e,p) in
 	let rec loop e = let e = Ast.map_expr loop e in (fst e,p) in
 	match parse_string ctx.com (head ^ s ^ ";}") p inl with
 	match parse_string ctx.com (head ^ s ^ ";}") p inl with
-	| _,[EClass { d_data = [{ cff_name = "main"; cff_kind = FFun { f_expr = Some e } }]},_] -> if inl then e else loop e
+	| _,[EClass { d_data = [{ cff_name = "main",null_pos; cff_kind = FFun { f_expr = Some e } }]},_] -> if inl then e else loop e
 	| _ -> raise Interp.Invalid_expr
 	| _ -> raise Interp.Invalid_expr
 
 
 let collect_toplevel_identifiers ctx =
 let collect_toplevel_identifiers ctx =
@@ -809,10 +809,20 @@ let unify_field_call ctx fa el args ret p inline =
 				candidates,(cf,err,p) :: failures
 				candidates,(cf,err,p) :: failures
 			end
 			end
 	in
 	in
+	let fail_fun () =
+		let tf = TFun(args,ret) in
+		[],tf,(fun ethis p_field ->
+			let e1 = mk (TField(ethis,mk_fa cf)) tf p_field in
+			mk (TCall(e1,[])) ret p)
+	in
 	match candidates with
 	match candidates with
 	| [t,cf] ->
 	| [t,cf] ->
-		let el,tf,mk_call = attempt_call t cf in
-		List.map fst el,tf,mk_call
+		begin try
+			let el,tf,mk_call = attempt_call t cf in
+			List.map fst el,tf,mk_call
+		with Error _ when ctx.com.display <> DMNone ->
+			fail_fun();
+		end
 	| _ ->
 	| _ ->
 		let candidates,failures = loop candidates in
 		let candidates,failures = loop candidates in
 		let fail () =
 		let fail () =
@@ -2829,10 +2839,8 @@ and type_vars ctx vl p =
 			) in
 			) in
 			if v.[0] = '$' && ctx.com.display = DMNone then error "Variables names starting with a dollar are not allowed" p;
 			if v.[0] = '$' && ctx.com.display = DMNone then error "Variables names starting with a dollar are not allowed" p;
 			let v,e = add_local ctx v t pv, e in
 			let v,e = add_local ctx v t pv, e in
-			if Display.is_display_position pv then begin
-				ctx.display_handled <- true;
+			if Display.is_display_position pv then
 				Display.display_variable ctx.com.display v;
 				Display.display_variable ctx.com.display v;
-			end;
 			v,e
 			v,e
 		with
 		with
 			Error (e,p) ->
 			Error (e,p) ->
@@ -2852,6 +2860,8 @@ and format_string ctx s p =
 	let min = ref (p.pmin + 1) in
 	let min = ref (p.pmin + 1) in
 	let add_expr (enext,p) len =
 	let add_expr (enext,p) len =
 		min := !min + len;
 		min := !min + len;
+		if ctx.in_display && Display.encloses_position !Parser.resume_display p then
+			raise (Display.DisplaySubExpression (enext,p));
 		match !e with
 		match !e with
 		| None -> e := Some (enext,p)
 		| None -> e := Some (enext,p)
 		| Some prev ->
 		| Some prev ->
@@ -3226,10 +3236,8 @@ and type_try ctx e1 catches with_type p =
 		check_unreachable acc t2 (pos e);
 		check_unreachable acc t2 (pos e);
 		let locals = save_locals ctx in
 		let locals = save_locals ctx in
 		let v = add_local ctx v t pv in
 		let v = add_local ctx v t pv in
-		if Display.is_display_position pv then begin
-			ctx.display_handled <- true;
+		if Display.is_display_position pv then
 			Display.display_variable ctx.com.display v;
 			Display.display_variable ctx.com.display v;
-		end;
 		let e = type_expr ctx e with_type in
 		let e = type_expr ctx e with_type in
 		v.v_type <- t2;
 		v.v_type <- t2;
 		locals();
 		locals();
@@ -3744,7 +3752,6 @@ and handle_display ctx e_ast iscall with_type p =
 	let old = ctx.in_display,ctx.in_call_args in
 	let old = ctx.in_display,ctx.in_call_args in
 	ctx.in_display <- true;
 	ctx.in_display <- true;
 	ctx.in_call_args <- false;
 	ctx.in_call_args <- false;
-	ctx.display_handled <- true;
 	let get_submodule_fields path =
 	let get_submodule_fields path =
 		let m = Hashtbl.find ctx.g.modules path in
 		let m = Hashtbl.find ctx.g.modules path in
 		let tl = List.filter (fun t -> path <> (t_infos t).mt_path && not (t_infos t).mt_private) m.m_types in
 		let tl = List.filter (fun t -> path <> (t_infos t).mt_path && not (t_infos t).mt_private) m.m_types in
@@ -3766,6 +3773,11 @@ and handle_display ctx e_ast iscall with_type p =
 		with Not_found ->
 		with Not_found ->
 			raise err
 			raise err
 		end
 		end
+	| Display.DisplaySubExpression e ->
+		ctx.in_display <- false;
+		let e = type_expr ctx e Value in
+		ctx.in_display <- true;
+		e
 	in
 	in
 	let e = match with_type with
 	let e = match with_type with
 		| WithType t -> (try Codegen.AbstractCast.cast_or_unify_raise ctx t e e.epos with Error (Unify l,p) -> e)
 		| WithType t -> (try Codegen.AbstractCast.cast_or_unify_raise ctx t e e.epos with Error (Unify l,p) -> e)
@@ -5221,7 +5233,6 @@ let rec create com =
 		curfun = FunStatic;
 		curfun = FunStatic;
 		in_loop = false;
 		in_loop = false;
 		in_display = false;
 		in_display = false;
-		display_handled = false;
 		in_macro = Common.defined com Define.Macro;
 		in_macro = Common.defined com Define.Macro;
 		ret = mk_mono();
 		ret = mk_mono();
 		locals = PMap.empty;
 		locals = PMap.empty;