Browse Source

support display on methods

Simon Krajewski 9 years ago
parent
commit
308f25a89e

+ 1 - 0
src/typing/typecore.ml

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

+ 10 - 0
src/typing/typeload.ml

@@ -2541,6 +2541,15 @@ module ClassInitializer = struct
 						cf.cf_type <- t
 					| _ ->
 						let e , fargs = type_function ctx args ret fmode fd is_display_field p in
+						if 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 (DisplayPosition [cf.cf_pos]);
+								| DMUsage -> cf.cf_meta <- (Meta.Usage,[],p) :: cf.cf_meta;
+								| DMType -> raise (DisplayTypes [cf.cf_type])
+								| _ -> ()
+						end;
 						let tf = {
 							tf_args = fargs;
 							tf_type = ret;
@@ -3347,6 +3356,7 @@ let type_types_into_module ctx m tdecls p =
 		untyped = false;
 		in_macro = ctx.in_macro;
 		in_display = false;
+		display_handled = false;
 		in_loop = false;
 		opened = [];
 		in_call_args = false;

+ 2 - 0
src/typing/typer.ml

@@ -3737,6 +3737,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 and handle_display ctx e_ast iscall with_type p =
 	let old = ctx.in_display in
 	ctx.in_display <- true;
+	ctx.display_handled <- true;
 	let get_submodule_fields path =
 		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
@@ -5198,6 +5199,7 @@ let rec create com =
 		curfun = FunStatic;
 		in_loop = false;
 		in_display = false;
+		display_handled = false;
 		in_macro = Common.defined com Define.Macro;
 		ret = mk_mono();
 		locals = PMap.empty;

+ 1 - 1
tests/misc/projects/Issue5122/compile.hxml

@@ -1 +1 @@
---display Main.hx@131@type
+--display Main.hx@126@type