Browse Source

deal with Dynamic display (closes #5651)

Simon Krajewski 9 years ago
parent
commit
0c6412ea27
4 changed files with 23 additions and 16 deletions
  1. 15 15
      src/display/display.ml
  2. 6 0
      src/typing/type.ml
  3. 1 1
      src/typing/typeload.ml
  4. 1 0
      src/typing/typer.ml

+ 15 - 15
src/display/display.ml

@@ -104,19 +104,22 @@ let find_before_pos com e =
 	in
 	in
 	map e
 	map e
 
 
-let display_type dm t p =
-	try
-		let mt = module_type_of_type t in
-		begin match dm.dms_kind 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 (DisplayType (t,p))
+let display_module_type dm mt p = match dm.dms_kind 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 (DisplayType (type_of_module_type mt,p))
+	| _ -> ()
+
+let rec display_type dm t p = match dm.dms_kind with
+	| DMType -> raise (DisplayType (t,p))
+	| _ ->
+		try display_module_type dm (module_type_of_type t) p
+		with Exit -> match follow t,follow !t_dynamic_def with
+			| _,TDynamic _ -> () (* sanity check in case it's still t_dynamic *)
+			| TDynamic _,_ -> display_type dm !t_dynamic_def p
 			| _ -> ()
 			| _ -> ()
-		end
-	with Exit ->
-		()
 
 
 let check_display_type ctx t p =
 let check_display_type ctx t p =
 	let add_type_hint () =
 	let add_type_hint () =
@@ -131,9 +134,6 @@ let check_display_type ctx t p =
 	| DMUsage _ -> add_type_hint(); maybe_display_type()
 	| DMUsage _ -> add_type_hint(); maybe_display_type()
 	| _ -> maybe_display_type()
 	| _ -> maybe_display_type()
 
 
-let display_module_type dm mt =
-	display_type dm (type_of_module_type mt)
-
 let display_variable dm v p = match dm.dms_kind with
 let display_variable dm v p = match dm.dms_kind with
 	| DMPosition -> raise (DisplayPosition [v.v_pos])
 	| DMPosition -> raise (DisplayPosition [v.v_pos])
 	| DMUsage _ -> v.v_meta <- (Meta.Usage,[],v.v_pos) :: v.v_meta;
 	| DMUsage _ -> v.v_meta <- (Meta.Usage,[],v.v_pos) :: v.v_meta;

+ 6 - 0
src/typing/type.ml

@@ -347,6 +347,12 @@ let mk_mono() = TMono (ref None)
 
 
 let rec t_dynamic = TDynamic t_dynamic
 let rec t_dynamic = TDynamic t_dynamic
 
 
+(* We use this for display purposes because otherwise we never see the Dynamic type that
+   is defined in StdTypes.hx. This is set each time a typer is created, but this is fine
+   because Dynamic is the same in all contexts. If this ever changes we'll have to review
+   how we handle this. *)
+let t_dynamic_def = ref t_dynamic
+
 let tfun pl r = TFun (List.map (fun t -> "",false,t) pl,r)
 let tfun pl r = TFun (List.map (fun t -> "",false,t) pl,r)
 
 
 let fun_args l = List.map (fun (a,c,t) -> a, c <> None, t) l
 let fun_args l = List.map (fun (a,c,t) -> a, c <> None, t) l

+ 1 - 1
src/typing/typeload.ml

@@ -454,7 +454,7 @@ let rec load_instance ?(allow_display=false) ctx (t,pn) allow_no_params p =
 		end else if path = ([],"Dynamic") then
 		end else if path = ([],"Dynamic") then
 			match t.tparams with
 			match t.tparams with
 			| [] -> t_dynamic
 			| [] -> t_dynamic
-			| [TPType t] -> TDynamic (load_complex_type ctx false p t)
+			| [TPType t] -> TDynamic (load_complex_type ctx true p t)
 			| _ -> error "Too many parameters for Dynamic" p
 			| _ -> error "Too many parameters for Dynamic" p
 		else begin
 		else begin
 			if not is_rest && ctx.com.display.dms_error_policy <> EPIgnore && List.length types <> List.length t.tparams then error ("Invalid number of type parameters for " ^ s_type_path path) p;
 			if not is_rest && ctx.com.display.dms_error_policy <> EPIgnore && List.length types <> List.length t.tparams then error ("Invalid number of type parameters for " ^ s_type_path path) p;

+ 1 - 0
src/typing/typer.ml

@@ -5234,6 +5234,7 @@ let rec create com =
 			| "Float" -> ctx.t.tfloat <- TAbstract (a,[]);
 			| "Float" -> ctx.t.tfloat <- TAbstract (a,[]);
 			| "Int" -> ctx.t.tint <- TAbstract (a,[])
 			| "Int" -> ctx.t.tint <- TAbstract (a,[])
 			| "Bool" -> ctx.t.tbool <- TAbstract (a,[])
 			| "Bool" -> ctx.t.tbool <- TAbstract (a,[])
+			| "Dynamic" -> t_dynamic_def := TAbstract(a,List.map snd a.a_params);
 			| _ -> ());
 			| _ -> ());
 		| TEnumDecl e ->
 		| TEnumDecl e ->
 			()
 			()