2
0
Эх сурвалжийг харах

[typer] allow WithType to carry an expected name

utilize it for completion sorting and show it on hover
Simon Krajewski 7 жил өмнө
parent
commit
eec79c1e5e

+ 3 - 3
src/context/abstractCast.ml

@@ -12,10 +12,10 @@ let make_static_call ctx c cf a pl args t p =
 		match args with
 			| [e] ->
 				let e,f = push_this ctx e in
-				ctx.with_type_stack <- (WithType t) :: ctx.with_type_stack;
+				ctx.with_type_stack <- (WithType.with_type t) :: ctx.with_type_stack;
 				let e = match ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name [e] p with
-					| Some e -> type_expr ctx e Value
-					| None ->  type_expr ctx (EConst (Ident "null"),p) Value
+					| Some e -> type_expr ctx e WithType.value
+					| None ->  type_expr ctx (EConst (Ident "null"),p) WithType.value
 				in
 				ctx.with_type_stack <- List.tl ctx.with_type_stack;
 				f();

+ 14 - 9
src/context/display/displayEmitter.ml

@@ -14,13 +14,18 @@ open Common
 open Display
 open DisplayPosition
 
+let get_expected_name with_type = match with_type with
+	| WithType.Value (Some s) | WithType.WithType(_,Some s) -> Some s
+	| _ -> None
+
 let sort_fields l with_type tk =
 	let p = match tk with
 		| TKExpr p | TKField p -> Some p
 		| _ -> None
 	in
+	let expected_name = get_expected_name with_type in
 	let l = List.map (fun ci ->
-		let i = get_sort_index tk ci (Option.default Globals.null_pos p) in
+		let i = get_sort_index tk ci (Option.default Globals.null_pos p) (Option.map fst expected_name) in
 		ci,i
 	) l in
 	let sort l =
@@ -32,7 +37,7 @@ let sort_fields l with_type tk =
 		| _ -> Type.map dynamify_type_params t
 	in
 	let l = match with_type with
-		| WithType t when (match follow t with TMono _ -> false | _ -> true) ->
+		| WithType.WithType(t,_) when (match follow t with TMono _ -> false | _ -> true) ->
 			let rec comp item = match item.ci_type with
 				| None -> 9
 				| Some (t',_) ->
@@ -149,7 +154,7 @@ let display_module_type ctx mt p = match ctx.com.display.dms_kind with
 	| DMHover ->
 		let t = type_of_module_type mt in
 		let ct = completion_type_of_type ctx t in
-		raise_hover (make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some (t,ct))) p
+		raise_hover (make_ci_type (CompletionModuleType.of_module_type mt) ImportStatus.Imported (Some (t,ct))) None p
 	| _ -> ()
 
 let rec display_type ctx t p =
@@ -165,7 +170,7 @@ let rec display_type ctx t p =
 			| DMHover ->
 				let ct = completion_type_of_type ctx t in
 				let ci = make_ci_expr (mk (TConst TNull) t p) (t,ct) in
-				raise_hover ci p
+				raise_hover ci None p
 			| _ ->
 				()
 
@@ -204,7 +209,7 @@ let display_variable ctx v p = match ctx.com.display.dms_kind with
 	| DMUsage _ -> ReferencePosition.set (v.v_name,v.v_pos,KVar)
 	| DMHover ->
 		let ct = completion_type_of_type ctx ~values:(get_value_meta v.v_meta) v.v_type in
-		raise_hover (make_ci_local v (v.v_type,ct)) p
+		raise_hover (make_ci_local v (v.v_type,ct)) None p
 	| _ -> ()
 
 let display_field ctx origin scope cf p = match ctx.com.display.dms_kind with
@@ -230,7 +235,7 @@ let display_field ctx origin scope cf p = match ctx.com.display.dms_kind with
             | _ -> cf
         in
 		let ct = completion_type_of_type ctx ~values:(get_value_meta cf.cf_meta) cf.cf_type in
-		raise_hover (make_ci_class_field (CompletionClassField.make cf scope origin true) (cf.cf_type,ct)) p
+		raise_hover (make_ci_class_field (CompletionClassField.make cf scope origin true) (cf.cf_type,ct)) None p
 	| _ -> ()
 
 let maybe_display_field ctx origin scope cf p =
@@ -242,7 +247,7 @@ let display_enum_field ctx en ef p = match ctx.com.display.dms_kind with
 	| DMUsage _ -> ReferencePosition.set (ef.ef_name,ef.ef_name_pos,KEnumField)
 	| DMHover ->
 		let ct = completion_type_of_type ctx ef.ef_type in
-		raise_hover (make_ci_enum_field (CompletionEnumField.make ef (Self (TEnumDecl en)) true) (ef.ef_type,ct)) p
+		raise_hover (make_ci_enum_field (CompletionEnumField.make ef (Self (TEnumDecl en)) true) (ef.ef_type,ct)) None p
 	| _ -> ()
 
 let display_meta com meta p = match com.display.dms_kind with
@@ -256,7 +261,7 @@ let display_meta com meta p = match com.display.dms_kind with
 				if com.json_out = None then
 					raise_metadata ("<metadata>" ^ s ^ "</metadata>")
 				else
-					raise_hover (make_ci_metadata (Meta.to_string meta) (Some s)) p
+					raise_hover (make_ci_metadata (Meta.to_string meta) (Some s)) None p
 		end
 	| DMDefault ->
 		let all,_ = Meta.get_documentation_list() in
@@ -273,7 +278,7 @@ let check_display_metadata ctx meta =
 		List.iter (fun e ->
 			if encloses_display_position (pos e) then begin
 				let e = ExprPreprocessing.process_expr ctx.com e in
-				delay ctx PTypeField (fun _ -> ignore(type_expr ctx e Value));
+				delay ctx PTypeField (fun _ -> ignore(type_expr ctx e WithType.value));
 			end
 		) args
 	) meta

+ 19 - 1
src/context/display/displayException.ml

@@ -8,6 +8,7 @@ open Genjson
 type hover_result = {
 	hitem : CompletionItem.t;
 	hpos : pos;
+	hexpected : WithType.t option;
 }
 
 type kind =
@@ -28,7 +29,7 @@ let raise_statistics s = raise (DisplayException(Statistics s))
 let raise_module_symbols s = raise (DisplayException(ModuleSymbols s))
 let raise_metadata s = raise (DisplayException(Metadata s))
 let raise_signatures l isig iarg = raise (DisplayException(DisplaySignatures(l,isig,iarg)))
-let raise_hover item p = raise (DisplayException(DisplayHover({hitem = item;hpos = p})))
+let raise_hover item expected p = raise (DisplayException(DisplayHover({hitem = item;hpos = p;hexpected = expected})))
 let raise_position pl = raise (DisplayException(DisplayPosition pl))
 let raise_fields ckl cr po = raise (DisplayException(DisplayFields(ckl,cr,po)))
 let raise_package sl = raise (DisplayException(DisplayPackage sl))
@@ -65,10 +66,27 @@ let to_json ctx de =
 			"signatures",jlist fsig sigs;
 		]
 	| DisplayHover hover ->
+		let name_source_kind_to_int = function
+			| WithType.FunctionArgument -> 0
+			| WithType.StructureField -> 1
+		in
+		let ctx = Genjson.create_context GMFull in
+		let generate_name (name,kind) = jobject [
+			"name",jstring name;
+			"kind",jint (name_source_kind_to_int kind);
+		] in
+		let expected = match hover.hexpected with
+			| Some(WithType.WithType(t,name)) ->
+				jobject (("type",generate_type ctx t) :: (match name with None -> [] | Some name -> ["name",generate_name name]))
+			| Some(Value(Some name)) ->
+				jobject ["name",generate_name name]
+			| _ -> jnull
+		in
 		jobject [
 			"documentation",jopt jstring (CompletionItem.get_documentation hover.hitem);
 			"range",generate_pos_as_range hover.hpos;
 			"item",CompletionItem.to_json ctx hover.hitem;
+			"expected",expected;
 		]
 	| DisplayPosition pl ->
 		jarray (List.map generate_pos_as_location pl)

+ 1 - 1
src/context/display/displayFields.ml

@@ -234,7 +234,7 @@ let collect ctx e_ast e dk with_type p =
 	(* Add static extensions *)
 	let items = collect_static_extensions ctx items e p in
 	let items = PMap.fold (fun item acc -> item :: acc) items [] in
-	let items = sort_fields items Value (TKField p) in
+	let items = sort_fields items WithType.value (TKField p) in
 	try
 		let sl = string_list_of_expr_path_raise e_ast in
 		(* Add submodule fields *)

+ 1 - 1
src/context/display/displayToplevel.ml

@@ -262,7 +262,7 @@ let collect ctx tk with_type =
 
 		(* enum constructors of expected type *)
 		begin match with_type with
-			| WithType t ->
+			| WithType.WithType(t,_) ->
 				(try enum_ctors (module_type_of_type t) with Exit -> ())
 			| _ -> ()
 		end;

+ 3 - 13
src/context/typecore.ml

@@ -24,11 +24,6 @@ open Type
 open Error
 open DisplayTypes
 
-type with_type =
-	| NoValue
-	| Value
-	| WithType of t
-
 type type_patch = {
 	mutable tp_type : complex_type option;
 	mutable tp_remove : bool;
@@ -103,7 +98,7 @@ and typer = {
 	g : typer_globals;
 	mutable meta : metadata;
 	mutable this_stack : texpr list;
-	mutable with_type_stack : with_type list;
+	mutable with_type_stack : WithType.t list;
 	mutable call_argument_stack : expr list list;
 	(* variable *)
 	mutable pass : typer_pass;
@@ -135,8 +130,8 @@ exception Forbid_package of (string * path * pos) * pos list * string
 exception WithTypeError of error_msg * pos
 
 let make_call_ref : (typer -> texpr -> texpr list -> t -> pos -> texpr) ref = ref (fun _ _ _ _ _ -> assert false)
-let type_expr_ref : (typer -> expr -> with_type -> texpr) ref = ref (fun _ _ _ -> assert false)
-let type_block_ref : (typer -> expr list -> with_type -> pos -> texpr) ref = ref (fun _ _ _ _ -> assert false)
+let type_expr_ref : (typer -> expr -> WithType.t -> texpr) ref = ref (fun _ _ _ -> assert false)
+let type_block_ref : (typer -> expr list -> WithType.t -> pos -> texpr) ref = ref (fun _ _ _ _ -> assert false)
 let unify_min_ref : (typer -> texpr list -> t) ref = ref (fun _ _ -> assert false)
 let get_pattern_locals_ref : (typer -> expr -> Type.t -> (string, tvar * pos) PMap.t) ref = ref (fun _ _ _ -> assert false)
 let analyzer_run_on_expr_ref : (Common.context -> texpr -> texpr) ref = ref (fun _ _ -> assert false)
@@ -159,11 +154,6 @@ let type_expr ctx e with_type = (!type_expr_ref) ctx e with_type
 
 let unify_min ctx el = (!unify_min_ref) ctx el
 
-let s_with_type = function
-	| NoValue -> "NoValue"
-	| Value -> "Value"
-	| WithType t -> "WithType " ^ (s_type (print_context()) t)
-
 let make_static_this c p =
 	let ta = TAnon { a_fields = c.cl_statics; a_status = ref (Statics c) } in
 	mk (TTypeExpr (TClassDecl c)) ta p

+ 9 - 2
src/core/display/completionItem.ml

@@ -442,11 +442,18 @@ let get_index item = match item.ci_kind with
 	| ITExpression _ -> 12
 	| ITTypeParameter _ -> 13
 
-let get_sort_index tk item p = match item.ci_kind with
+let get_sort_index tk item p expected_name = match item.ci_kind with
 	| ITLocal v ->
 		let i = p.pmin - v.v_pos.pmin in
 		let i = if i < 0 then 0 else i in
-		0,(Printf.sprintf "%05i" i)
+		let s = Printf.sprintf "%05i" i in
+		let s = match expected_name with
+			| None -> s
+			| Some name ->
+				let i = StringError.levenshtein name v.v_name in
+				Printf.sprintf "%05i%s" i s
+		in
+		0,s
 	| ITClassField ccf ->
 		let open ClassFieldOrigin in
 		let i = match ccf.origin,ccf.scope with

+ 31 - 0
src/core/withType.ml

@@ -0,0 +1,31 @@
+open Type
+
+type expected_name_source =
+	| FunctionArgument
+	| StructureField
+
+type expected_name = string * expected_name_source
+
+type t =
+	| NoValue
+	| Value of expected_name option
+	| WithType of Type.t * expected_name option
+
+let with_type t = WithType(t,None)
+let with_argument t name = WithType(t,Some(name,FunctionArgument))
+let with_structure_field t name = WithType(t,Some(name,StructureField))
+let value = Value None
+let named_argument name = Value (Some(name,FunctionArgument))
+let named_structure_field name = Value (Some(name,StructureField))
+let no_value = NoValue
+
+let to_string = function
+	| NoValue -> "NoValue"
+	| Value None -> "Value"
+	| Value (Some(s,_)) -> "Value " ^ s
+	| WithType(t,s) ->
+		let name = match s with
+			| None -> "None"
+			| Some(s,_) -> s
+		in
+		Printf.sprintf "WithType(%s, %s)" (s_type (print_context()) t) name

+ 15 - 15
src/typing/calls.ml

@@ -97,7 +97,7 @@ let call_to_string ctx ?(resume=false) e =
 	ctx.meta <- (Meta.PrivateAccess,[],e.epos) :: ctx.meta;
 	let acc = type_field ~resume ctx e "toString" e.epos MCall in
 	ctx.meta <- List.tl ctx.meta;
-	!build_call_ref ctx acc [] (WithType ctx.t.tstring) e.epos
+	!build_call_ref ctx acc [] (WithType.with_type ctx.t.tstring) e.epos
 
 let rec unify_call_args' ctx el args r callp inline force_inline =
 	let in_call_args = ctx.in_call_args in
@@ -111,7 +111,7 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 	in
 	let mk_pos_infos t =
 		let infos = mk_infos ctx callp [] in
-		type_expr ctx infos (WithType t)
+		type_expr ctx infos (WithType.with_type t)
 	in
 	let rec default_value name t =
 		if is_pos_infos t then
@@ -128,9 +128,9 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 		default_value name t
 	in
 	(* let force_inline, is_extern = match cf with Some(TInst(c,_),f) -> is_forced_inline (Some c) f, c.cl_extern | _ -> false, false in *)
-	let type_against t e =
+	let type_against name t e =
 		try
-			let e = type_expr ctx e (WithType t) in
+			let e = type_expr ctx e (WithType.with_argument t name) in
 			AbstractCast.cast_or_unify_raise ctx t e e.epos
 		with Error(l,p) when (match l with Call_error _ | Module_not_found _ -> false | _ -> true) ->
 			raise (WithTypeError (l,p))
@@ -145,7 +145,7 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 		| _,[name,false,t] when (match follow t with TAbstract({a_path = ["haxe";"extern"],"Rest"},_) -> true | _ -> false) ->
 			begin match follow t with
 				| TAbstract({a_path=(["haxe";"extern"],"Rest")},[t]) ->
-					(try List.map (fun e -> type_against t e,false) el with WithTypeError(ul,p) -> arg_error ul name false p)
+					(try List.map (fun e -> type_against name t e,false) el with WithTypeError(ul,p) -> arg_error ul name false p)
 				| _ ->
 					assert false
 			end
@@ -167,7 +167,7 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 			end
 		| e :: el,(name,opt,t) :: args ->
 			begin try
-				let e = type_against t e in
+				let e = type_against name t e in
 				(e,opt) :: loop el args
 			with
 				WithTypeError (ul,p)->
@@ -326,7 +326,7 @@ let unify_field_call ctx fa el args ret p inline =
 		| _ ->  error "Invalid field type for generic call" p
 	in
 	begin match with_type with
-		| WithType t -> unify ctx ret t p
+		| WithType.WithType(t,_) -> unify ctx ret t p
 		| _ -> ()
 	end;
 	let el,_ = unify_call_args ctx el args ret p false false in
@@ -507,7 +507,7 @@ let rec acc_get ctx g p =
 	| AKMacro _ ->
 		assert false
 
-let rec build_call ctx acc el (with_type:with_type) p =
+let rec build_call ctx acc el (with_type:WithType.t) p =
 	match acc with
 	| AKInline (ethis,f,fmode,t) when Meta.has Meta.Generic f.cf_meta ->
 		type_generic_function ctx (ethis,fmode) el with_type p
@@ -559,7 +559,7 @@ let rec build_call ctx acc el (with_type:with_type) p =
 		let f = (match ethis.eexpr with
 		| TTypeExpr (TClassDecl c) ->
 			(match ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name el p with
-			| None -> (fun() -> type_expr ctx (EConst (Ident "null"),p) Value)
+			| None -> (fun() -> type_expr ctx (EConst (Ident "null"),p) WithType.value)
 			| Some (EMeta((Meta.MergeBlock,_,_),(EBlock el,_)),_) -> (fun () -> let e = (!type_block_ref) ctx el with_type p in mk (TMeta((Meta.MergeBlock,[],p), e)) e.etype e.epos)
 			| Some e -> (fun() -> type_expr ctx e with_type))
 		| _ ->
@@ -571,8 +571,8 @@ let rec build_call ctx acc el (with_type:with_type) p =
 						let eparam,f = push_this ctx ethis in
 						ethis_f := f;
 						let e = match ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name (eparam :: el) p with
-							| None -> (fun() -> type_expr ctx (EConst (Ident "null"),p) Value)
-							| Some e -> (fun() -> type_expr ctx e Value)
+							| None -> (fun() -> type_expr ctx (EConst (Ident "null"),p) WithType.value)
+							| Some e -> (fun() -> type_expr ctx e WithType.value)
 						in
 						e
 					else
@@ -631,11 +631,11 @@ let rec build_call ctx acc el (with_type:with_type) p =
 			loop (Abstract.get_underlying_type a tl)
 		| TMono _ ->
 			let t = mk_mono() in
-			let el = List.map (fun e -> type_expr ctx e Value) el in
+			let el = List.map (fun e -> type_expr ctx e WithType.value) el in
 			unify ctx (tfun (List.map (fun e -> e.etype) el) t) e.etype e.epos;
 			mk (TCall (e,el)) t p
 		| t ->
-			let el = List.map (fun e -> type_expr ctx e Value) el in
+			let el = List.map (fun e -> type_expr ctx e WithType.value) el in
 			let t = if t == t_dynamic then
 				t_dynamic
 			else if ctx.untyped then
@@ -663,7 +663,7 @@ let type_bind ctx (e : texpr) (args,ret) params p =
 		| (n,o,t) :: args , [] when o ->
 			let a = if is_pos_infos t then
 					let infos = mk_infos ctx p [] in
-					ordered_args @ [type_expr ctx infos (WithType t)]
+					ordered_args @ [type_expr ctx infos (WithType.with_argument t n)]
 				else if ctx.com.config.pf_pad_nulls then
 					(ordered_args @ [(mk (TConst TNull) t_dynamic p)])
 				else
@@ -677,7 +677,7 @@ let type_bind ctx (e : texpr) (args,ret) params p =
 			let v = alloc_var VGenerated (alloc_name n) (if o then ctx.t.tnull t else t) p in
 			loop args params given_args (missing_args @ [v,o]) (ordered_args @ [vexpr v])
 		| (n,o,t) :: args , param :: params ->
-			let e = type_expr ctx param (WithType t) in
+			let e = type_expr ctx param (WithType.with_argument t n) in
 			let e = AbstractCast.cast_or_unify ctx t e p in
 			let v = alloc_var VGenerated (alloc_name n) t (pos param) in
 			loop args params (given_args @ [v,o,Some e]) missing_args (ordered_args @ [vexpr v])

+ 7 - 7
src/typing/forLoop.ml

@@ -53,7 +53,7 @@ module IterationKind = struct
 		let e1 = try
 			AbstractCast.cast_or_unify_raise ctx t e p
 		with Error (Unify _,_) ->
-			let acc = !build_call_ref ctx (type_field ctx e s e.epos MCall) [] Value e.epos in
+			let acc = !build_call_ref ctx (type_field ctx e s e.epos MCall) [] WithType.value e.epos in
 			try
 				unify_raise ctx acc.etype t acc.epos;
 				acc
@@ -130,8 +130,8 @@ module IterationKind = struct
 				let e_tmp = make_local v_tmp v_tmp.v_pos in
 				let acc_next = type_field ~resume:true ctx e_tmp "next" p MCall in
 				let acc_hasNext = type_field ~resume:true ctx e_tmp "hasNext" p MCall in
-				let e_next = !build_call_ref ctx acc_next [] Value e.epos in
-				let e_hasNext = !build_call_ref ctx acc_hasNext [] Value e.epos in
+				let e_next = !build_call_ref ctx acc_next [] WithType.value e.epos in
+				let e_hasNext = !build_call_ref ctx acc_hasNext [] WithType.value e.epos in
 				IteratorAbstract(v_tmp,e_next,e_hasNext),e,e_next.etype
 			with Not_found ->
 				check_iterator ()
@@ -343,14 +343,14 @@ let type_for_loop ctx handle_display it e2 p =
 		| _ -> error "For expression should be 'v in expr'" (snd it)
 	in
 	let ik,e1 = loop None it in
-	let e1 = type_expr ctx e1 Value in
+	let e1 = type_expr ctx e1 WithType.value in
 	let old_loop = ctx.in_loop in
 	let old_locals = save_locals ctx in
 	ctx.in_loop <- true;
 	let e2 = Expr.ensure_block e2 in
 	let check_display (i,pi,dko) = match dko with
 		| None -> ()
-		| Some dk -> ignore(handle_display ctx (EConst(Ident i.v_name),i.v_pos) dk (WithType i.v_type))
+		| Some dk -> ignore(handle_display ctx (EConst(Ident i.v_name),i.v_pos) dk (WithType.with_type i.v_type))
 	in
 	match ik with
 	| IKNormal(i,pi,dko) ->
@@ -373,8 +373,8 @@ let type_for_loop ctx handle_display it e2 p =
 		end;
 		let vtmp = gen_local ctx e1.etype e1.epos in
 		let etmp = make_local vtmp vtmp.v_pos in
-		let ehasnext = !build_call_ref ctx (type_field ctx etmp "hasNext" etmp.epos MCall) [] Value etmp.epos in
-		let enext = !build_call_ref ctx (type_field ctx etmp "next" etmp.epos MCall) [] Value etmp.epos in
+		let ehasnext = !build_call_ref ctx (type_field ctx etmp "hasNext" etmp.epos MCall) [] WithType.value etmp.epos in
+		let enext = !build_call_ref ctx (type_field ctx etmp "next" etmp.epos MCall) [] WithType.value etmp.epos in
 		let v = gen_local ctx pt e1.epos in
 		let ev = make_local v v.v_pos in
 		let ekey = Calls.acc_get ctx (type_field ctx ev "key" ev.epos MGet) ev.epos in

+ 1 - 1
src/typing/generic.ml

@@ -19,7 +19,7 @@ type generic_context = {
 let generic_check_const_expr ctx t =
 	match follow t with
 	| TInst({cl_kind = KExpr e},_) ->
-		let e = type_expr {ctx with locals = PMap.empty} e Value in
+		let e = type_expr {ctx with locals = PMap.empty} e WithType.value in
 		e.etype,Some e
 	| _ -> t,None
 

+ 4 - 4
src/typing/macroContext.ml

@@ -199,10 +199,10 @@ let make_macro_api ctx p =
 		);
 		MacroApi.parse_string = parse_expr_string;
 		MacroApi.type_expr = (fun e ->
-			typing_timer ctx true (fun() -> type_expr ctx e Value)
+			typing_timer ctx true (fun() -> type_expr ctx e WithType.value)
 		);
 		MacroApi.type_macro_expr = (fun e ->
-			let e = typing_timer ctx true (fun() -> type_expr ctx e Value) in
+			let e = typing_timer ctx true (fun() -> type_expr ctx e WithType.value) in
 			let rec loop e = match e.eexpr with
 				| TField(_,FStatic(c,({cf_kind = Method _} as cf))) -> ignore(!load_macro_ref ctx false c.cl_path cf.cf_name e.epos)
 				| _ -> Type.iter loop e
@@ -264,7 +264,7 @@ let make_macro_api ctx p =
 		);
 		MacroApi.get_expected_type = (fun() ->
 			match ctx.with_type_stack with
-				| (WithType t) :: _ -> Some t
+				| (WithType.WithType(t,_)) :: _ -> Some t
 				| _ -> None
 		);
 		MacroApi.get_call_arguments = (fun() ->
@@ -760,7 +760,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 				let mint = Interp.get_ctx() in
 				match call() with
 				| None -> (fun() -> raise MacroApi.Abort)
-				| Some e -> Interp.eval_delayed mint (type_expr ctx e Value)
+				| Some e -> Interp.eval_delayed mint (type_expr ctx e WithType.value)
 			);
 		);
 		ctx.m.curmod.m_extra.m_time <- -1.; (* disable caching for modules having macro-in-macro *)

+ 18 - 18
src/typing/matcher.ml

@@ -216,7 +216,7 @@ module Pattern = struct
 		let try_typing e =
 			let old = ctx.untyped in
 			ctx.untyped <- true;
-			let e = try type_expr ctx e (WithType t) with exc -> ctx.untyped <- old; raise exc in
+			let e = try type_expr ctx e (WithType.with_type t) with exc -> ctx.untyped <- old; raise exc in
 			ctx.untyped <- old;
 			match e.eexpr with
 				| TTypeExpr mt ->
@@ -312,7 +312,7 @@ module Pattern = struct
 				let v = add_local final s p in
 				PatVariable v
 			| ECall(e1,el) ->
-				let e1 = type_expr ctx e1 (WithType t) in
+				let e1 = type_expr ctx e1 (WithType.with_type t) in
 				begin match e1.eexpr,follow e1.etype with
 					| TField(_, FEnum(en,ef)),TFun(_,TEnum(_,tl)) ->
 						let monos = List.map (fun _ -> mk_mono()) ef.ef_params in
@@ -445,7 +445,7 @@ module Pattern = struct
 						let v = add_local false s p in
 						begin match dko with
 						| None -> ()
-						| Some dk -> ignore(TyperDisplay.display_expr ctx e (mk (TLocal v) v.v_type p) dk (WithType t) p);
+						| Some dk -> ignore(TyperDisplay.display_expr ctx e (mk (TLocal v) v.v_type p) dk (WithType.with_type t) p);
 						end;
 						let pat = make pctx false t e2 in
 						PatBind(v,pat)
@@ -458,7 +458,7 @@ module Pattern = struct
 				let restore = save_locals ctx in
 				ctx.locals <- pctx.ctx_locals;
 				let v = add_local false "_" null_pos in
-				let e1 = type_expr ctx e1 Value in
+				let e1 = type_expr ctx e1 WithType.value in
 				v.v_name <- "tmp";
 				restore();
 				let pat = make pctx toplevel e1.etype e2 in
@@ -470,18 +470,18 @@ module Pattern = struct
 				let pat = loop e in
 				let locals' = ctx.locals in
 				ctx.locals <- locals;
-				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType t));
+				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType.with_type t));
 				ctx.locals <- locals';
 				pat
 			(* For signature completion, we don't want to recurse into the inner pattern because there's probably
 			   a EDisplay(_,DMMarked) in there. We can handle display immediately because inner patterns should not
 			   matter (#7326) *)
 			| EDisplay(e1,DKCall) ->
-				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType t));
+				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType.with_type t));
 				loop e1
 			| EDisplay(e,dk) ->
 				let pat = loop e in
-				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType t));
+				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType.with_type t));
 				pat
 			| EMeta((Meta.StoredTypedExpr,_,_),e1) ->
 				let e1 = MacroContext.type_stored_expr ctx e1 in
@@ -537,16 +537,16 @@ module Case = struct
 		unapply_type_parameters ctx.type_params monos;
 		let eg = match eg with
 			| None -> None
-			| Some e -> Some (type_expr ctx e Value)
+			| Some e -> Some (type_expr ctx e WithType.value)
 		in
 		let eo = match eo_ast,with_type with
-			| None,WithType t ->
+			| None,WithType.WithType(t,_) ->
 				unify ctx ctx.t.tvoid t (pos e);
 				None
 			| None,_ ->
 				None
-			| Some e,WithType t ->
-				let e = type_expr ctx e (WithType (map t)) in
+			| Some e,WithType.WithType(t,_) ->
+				let e = type_expr ctx e (WithType.with_type (map t)) in
 				let e = AbstractCast.cast_or_unify ctx (map t) e e.epos in
 				Some e
 			| Some e,_ ->
@@ -1354,7 +1354,7 @@ module TexprConverter = struct
 						let loop toplevel params dt =
 							try Some (loop toplevel params dt)
 							with Not_exhaustive -> match with_type,finiteness with
-								| NoValue,Infinite -> None
+								| WithType.NoValue,Infinite -> None
 								| _,CompileTimeFinite when unmatched = [] -> None
 								| _ when ctx.com.display.DisplayMode.dms_error_policy = DisplayMode.EPIgnore -> None
 								| _ -> report_not_exhaustive e_subject unmatched
@@ -1473,13 +1473,13 @@ module Match = struct
 		let match_debug = Meta.has (Meta.Custom ":matchDebug") ctx.curfield.cf_meta in
 		let rec loop e = match fst e with
 			| EArrayDecl el when (match el with [(EFor _ | EWhile _),_] -> false | _ -> true) ->
-				let el = List.map (fun e -> type_expr ctx e Value) el in
+				let el = List.map (fun e -> type_expr ctx e WithType.value) el in
 				let t = tuple_type (List.map (fun e -> e.etype) el) in
 				t,el
 			| EParenthesis e1 ->
 				loop e1
 			| _ ->
-				let e = type_expr ctx e Value in
+				let e = type_expr ctx e WithType.value in
 				e.etype,[e]
 		in
 		let t,subjects = loop e in
@@ -1489,7 +1489,7 @@ module Match = struct
 			| Some (eo,p) -> cases @ [[EConst (Ident "_"),p],None,eo,p]
 		in
 		let tmono,with_type = match with_type with
-			| WithType t -> (match follow t with TMono _ -> Some t,Value | _ -> None,with_type)
+			| WithType.WithType(t,_) -> (match follow t with TMono _ -> Some t,WithType.value | _ -> None,with_type)
 			| _ -> None,with_type
 		in
 		let cases = List.map (fun (el,eg,eo,p) ->
@@ -1499,11 +1499,11 @@ module Match = struct
 		) cases in
 		let infer_switch_type () =
 			match with_type with
-				| NoValue -> ctx.t.tvoid
-				| Value ->
+				| WithType.NoValue -> ctx.t.tvoid
+				| WithType.Value(_) ->
 					let el = List.map (fun (case,_,_) -> match case.Case.case_expr with Some e -> e | None -> mk (TBlock []) ctx.t.tvoid p) cases in
 					unify_min ctx el
-				| WithType t -> t
+				| WithType.WithType(t,_) -> t
 		in
 		if match_debug then begin
 			print_endline "CASES BEGIN";

+ 3 - 3
src/typing/typeload.ml

@@ -193,7 +193,7 @@ let check_param_constraints ctx types t pl c p =
 				in
 				match follow t with
 				| TInst({cl_kind = KExpr e},_) ->
-					let e = type_expr {ctx with locals = PMap.empty} e (WithType ti) in
+					let e = type_expr {ctx with locals = PMap.empty} e (WithType.with_type ti) in
 					begin try unify_raise ctx e.etype ti p
 					with Error (Unify _,_) -> fail() end
 				| _ ->
@@ -260,7 +260,7 @@ let rec load_instance' ctx (t,p) allow_no_params =
 						| EConst (Int i) -> "I" ^ i
 						| EConst (Float f) -> "F" ^ f
 						| EDisplay _ ->
-							ignore(type_expr ctx e Value);
+							ignore(type_expr ctx e WithType.value);
 							"Expr"
 						| _ -> "Expr"
 					) in
@@ -837,7 +837,7 @@ let handle_path_display ctx path p =
 	in
 	match ImportHandling.convert_import_to_something_usable !DisplayPosition.display_position path,ctx.com.display.dms_kind with
 		| (IDKPackage [_],p),DMDefault ->
-			let fields = DisplayToplevel.collect ctx TKType Typecore.NoValue in
+			let fields = DisplayToplevel.collect ctx TKType WithType.no_value in
 			raise_fields fields CRImport (Some p)
 		| (IDKPackage sl,p),DMDefault ->
 			let sl = match List.rev sl with

+ 2 - 2
src/typing/typeloadFunction.ml

@@ -51,7 +51,7 @@ let save_field_state ctx =
 let type_var_field ctx t e stat do_display p =
 	if stat then ctx.curfun <- FunStatic else ctx.curfun <- FunMember;
 	let e = if do_display then Display.ExprPreprocessing.process_expr ctx.com e else e in
-	let e = type_expr ctx e (WithType t) in
+	let e = type_expr ctx e (WithType.with_type t) in
 	let e = AbstractCast.cast_or_unify ctx t e p in
 	match t with
 	| TType ({ t_path = ([],"UInt") },[]) | TAbstract ({ a_path = ([],"UInt") },[]) when stat -> { e with etype = t }
@@ -72,7 +72,7 @@ let type_function_arg_value ctx t c do_display =
 		| Some e ->
 			let p = pos e in
 			let e = if do_display then Display.ExprPreprocessing.process_expr ctx.com e else e in
-			let e = ctx.g.do_optimize ctx (type_expr ctx e (WithType t)) in
+			let e = ctx.g.do_optimize ctx (type_expr ctx e (WithType.with_type t)) in
 			unify ctx e.etype t p;
 			let rec loop e = match e.eexpr with
 				| TConst c -> Some c

+ 1 - 1
src/typing/typeloadModule.ml

@@ -116,7 +116,7 @@ module StrictMeta = struct
 			in
 
 			let left = type_expr ctx left_side NoValue in
-			let right = type_expr ctx expr (WithType left.etype) in
+			let right = type_expr ctx expr (WithType.with_type left.etype) in
 			unify ctx left.etype right.etype (snd expr);
 			(EBinop(Ast.OpAssign,fieldexpr,process_meta_argument ctx right), pos)
 		) fields_to_check

+ 69 - 69
src/typing/typer.ml

@@ -109,7 +109,7 @@ let get_abstract_froms a pl =
 let maybe_type_against_enum ctx f with_type iscall p =
 	try
 		begin match with_type with
-		| WithType t ->
+		| WithType.WithType(t,_) ->
 			let rec loop stack t = match follow t with
 				| TEnum (en,_) ->
 					true,en.e_path,en.e_names,TEnumDecl en
@@ -488,7 +488,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 	match op with
 	| OpAssign ->
 		let e1 = type_access ctx (fst e1) (snd e1) MSet in
-		let tt = (match e1 with AKNo _ | AKInline _ | AKUsing _ | AKMacro _ | AKAccess _ -> Value | AKFieldSet(_,_,_,t) | AKSet(_,t,_) -> WithType t | AKExpr e -> WithType e.etype) in
+		let tt = (match e1 with AKNo _ | AKInline _ | AKUsing _ | AKMacro _ | AKAccess _ -> WithType.value | AKFieldSet(_,_,_,t) | AKSet(_,t,_) -> WithType.with_type t | AKExpr e -> WithType.with_type e.etype) in
 		let e2 = type_expr ctx e2 tt in
 		(match e1 with
 		| AKNo s -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
@@ -635,7 +635,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			let ekey,ekey' = maybe_bind_to_temp ekey in
 			let ebase,ebase' = maybe_bind_to_temp ebase in
 			let eget = mk_array_get_call ctx (cf_get,tf_get,r_get,ekey,None) c ebase p in
-			let eget = type_binop2 ctx op eget e2 true (WithType eget.etype) p in
+			let eget = type_binop2 ctx op eget e2 true (WithType.with_type eget.etype) p in
 			unify ctx eget.etype r_get p;
 			let cf_set,tf_set,r_set,ekey,eget = AbstractCast.find_array_access ctx a tl ekey (Some eget) p in
 			let eget = match eget with None -> assert false | Some e -> e in
@@ -643,7 +643,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			let e = match cf_set.cf_expr,cf_get.cf_expr with
 				| None,None ->
 					let ea = mk (TArray(ebase,ekey)) r_get p in
-					mk (TBinop(OpAssignOp op,ea,type_expr ctx e2 (WithType r_get))) r_set p
+					mk (TBinop(OpAssignOp op,ea,type_expr ctx e2 (WithType.with_type r_get))) r_set p
 				| Some _,Some _ ->
 					let ef_set = mk (TField(et,(FStatic(c,cf_set)))) tf_set p in
 					let el = [make_call ctx ef_set [ebase;ekey;eget] r_set p] in
@@ -666,25 +666,25 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 		(* If the with_type is an abstract which has exactly one applicable @:op method, we can promote it
 		   to the individual arguments (issue #2786). *)
 		let wt = match with_type with
-			| WithType t ->
+			| WithType.WithType(t,_) ->
 				begin match follow t with
 					| TAbstract(a,_) ->
 						begin match List.filter (fun (o,_) -> o = OpAssignOp(op) || o == op) a.a_ops with
 							| [_] -> with_type
-							| _ -> Value
+							| _ -> WithType.value
 						end
 					| _ ->
-						Value
+						WithType.value
 				end
 			| _ ->
-				Value
+				WithType.value
 		in
 		let e1 = type_expr ctx e1 wt in
 		type_binop2 ctx op e1 e2 is_assign_op wt p
 
 and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 	let with_type = match op with
-		| OpEq | OpNotEq | OpLt | OpLte | OpGt | OpGte -> WithType e1.etype
+		| OpEq | OpNotEq | OpLt | OpLte | OpGt | OpGte -> WithType.with_type e1.etype
 		| _ -> wt
 	in
 	let e2 = type_expr ctx e2 with_type in
@@ -1108,7 +1108,7 @@ and type_unop ctx op flag e p =
 			let eget = (EField ((EConst (Ident v.v_name),p),cf.cf_name),p) in
 			match flag with
 			| Prefix ->
-				let get = type_binop ctx op eget one false Value p in
+				let get = type_binop ctx op eget one false WithType.value p in
 				unify ctx get.etype t p;
 				l();
 				mk (TBlock [
@@ -1118,8 +1118,8 @@ and type_unop ctx op flag e p =
 			| Postfix ->
 				let v2 = gen_local ctx t p in
 				let ev2 = mk (TLocal v2) t p in
-				let get = type_expr ctx eget Value in
-				let plusone = type_binop ctx op (EConst (Ident v2.v_name),p) one false Value p in
+				let get = type_expr ctx eget WithType.value in
+				let plusone = type_binop ctx op (EConst (Ident v2.v_name),p) one false WithType.value p in
 				unify ctx get.etype t p;
 				l();
 				mk (TBlock [
@@ -1348,7 +1348,7 @@ and handle_efield ctx e p mode =
 									(* if there was no module name part, last guess is that we're trying to get package completion *)
 									if ctx.in_display then begin
 										if ctx.com.json_out = None then raise (Parser.TypePath (List.map (fun (n,_,_) -> n) (List.rev acc),None,false,p))
-										else raise_fields (DisplayToplevel.collect ctx TKType NoValue) CRTypeHint (Some p0);
+										else raise_fields (DisplayToplevel.collect ctx TKType WithType.no_value) CRTypeHint (Some p0);
 									end;
 									raise e)
 		in
@@ -1394,7 +1394,7 @@ and type_access ctx e p mode =
 	| EConst (Ident s) ->
 		type_ident ctx s p mode
 	| EField (e1,"new") ->
-		let e1 = type_expr ctx e1 Value in
+		let e1 = type_expr ctx e1 WithType.value in
 		begin match e1.eexpr with
 			| TTypeExpr (TClassDecl c) ->
 				if mode = MSet then error "Cannot set constructor" p;
@@ -1428,11 +1428,11 @@ and type_access ctx e p mode =
 	| EArray (e1,e2) ->
 		type_array_access ctx e1 e2 p mode
 	| _ ->
-		AKExpr (type_expr ctx (e,p) Value)
+		AKExpr (type_expr ctx (e,p) WithType.value)
 
 and type_array_access ctx e1 e2 p mode =
-	let e1 = type_expr ctx e1 Value in
-	let e2 = type_expr ctx e2 Value in
+	let e1 = type_expr ctx e1 WithType.value in
+	let e2 = type_expr ctx e2 WithType.value in
 	let has_abstract_array_access = ref false in
 	try
 		(match follow e1.etype with
@@ -1481,7 +1481,7 @@ and type_vars ctx vl p =
 			let e = (match e with
 				| None -> None
 				| Some e ->
-					let e = type_expr ctx e (WithType t) in
+					let e = type_expr ctx e (WithType.with_type t) in
 					let e = AbstractCast.cast_or_unify ctx t e p in
 					Some e
 			) in
@@ -1614,7 +1614,7 @@ and type_block ctx el with_type p =
 	let rec loop acc = function
 		| [] -> List.rev acc
 		| e :: l ->
-			let acc = try merge acc (type_expr ctx e (if l = [] then with_type else NoValue)) with Error (e,p) -> check_error ctx e p; acc in
+			let acc = try merge acc (type_expr ctx e (if l = [] then with_type else WithType.no_value)) with Error (e,p) -> check_error ctx e p; acc in
 			loop acc l
 	in
 	let l = loop [] el in
@@ -1628,7 +1628,7 @@ and type_block ctx el with_type p =
 and type_object_decl ctx fl with_type p =
 	let dynamic_parameter = ref None in
 	let a = (match with_type with
-	| WithType t ->
+	| WithType.WithType(t,_) ->
 		let rec loop seen t =
 			match follow t with
 			| TAnon a -> ODKWithStructure a
@@ -1667,14 +1667,14 @@ and type_object_decl ctx fl with_type p =
 						if ctx.in_display && DisplayPosition.encloses_display_position pn then DisplayEmitter.display_field ctx Unknown CFSMember cf pn;
 						cf.cf_type
 				in
-				let e = type_expr ctx e (WithType t) in
+				let e = type_expr ctx e (WithType.with_structure_field t n) in
 				let e = AbstractCast.cast_or_unify ctx t e e.epos in
 				let e = if is_null t && not (is_null e.etype) then mk (TCast(e,None)) (ctx.t.tnull e.etype) e.epos else e in
 				(try type_eq EqStrict e.etype t; e with Unify_error _ -> mk (TCast (e,None)) t e.epos)
 			with Not_found ->
 				if is_valid then
 					extra_fields := n :: !extra_fields;
-				type_expr ctx e Value
+				type_expr ctx e WithType.value
 			in
 			if is_valid then begin
 				if starts_with n '$' then error "Field names starting with a dollar are not allowed" p;
@@ -1700,7 +1700,7 @@ and type_object_decl ctx fl with_type p =
 		let rec loop (l,acc) ((f,pf,qs),e) =
 			let is_valid = Lexer.is_valid_identifier f in
 			if PMap.mem f acc then error ("Duplicate field in object declaration : " ^ f) p;
-			let e = type_expr ctx e Value in
+			let e = type_expr ctx e (WithType.named_structure_field f) in
 			(match follow e.etype with TAbstract({a_path=[],"Void"},_) -> error "Fields of type Void are not allowed in structures" e.epos | _ -> ());
 			let cf = mk_field f e.etype (punion pf e.epos) pf in
 			if ctx.in_display && DisplayPosition.encloses_display_position pf then DisplayEmitter.display_field ctx Unknown CFSMember cf pf;
@@ -1793,7 +1793,7 @@ and type_new ctx path el with_type p =
 			with Generic.Generic_Exception _ as exc ->
 				(* If we have an expected type, just use that (issue #3804) *)
 				begin match with_type with
-					| WithType t ->
+					| WithType.WithType(t,_) ->
 						begin match follow t with
 							| TMono _ -> raise exc
 							| t -> t
@@ -1818,7 +1818,7 @@ and type_new ctx path el with_type p =
 	try begin match t with
 	| TInst ({cl_kind = KTypeParameter tl} as c,params) ->
 		if not (TypeloadCheck.is_generic_parameter ctx c) then error "Only generic type parameters can be constructed" p;
-		let el = List.map (fun e -> type_expr ctx e Value) el in
+		let el = List.map (fun e -> type_expr ctx e WithType.value) el in
  		if not (has_constructible_constraint ctx tl el p) then raise_error (No_constructor (TClassDecl c)) p;
 		mk (TNew (c,params,el)) t p
 	| TAbstract({a_impl = Some c} as a,tl) when not (Meta.has Meta.MultiType a.a_meta) ->
@@ -1901,10 +1901,10 @@ and type_try ctx e1 catches with_type p =
 		((v,e) :: acc1),(e :: acc2)
 	) ([],[e1]) catches in
 	let t = match with_type with
-		| NoValue -> ctx.t.tvoid
-		| Value -> unify_min ctx el
-		| WithType t when (match follow t with TMono _ -> true | _ -> false) -> unify_min ctx el
-		| WithType t ->
+		| WithType.NoValue -> ctx.t.tvoid
+		| WithType.Value _ -> unify_min ctx el
+		| WithType.WithType(t,_) when (match follow t with TMono _ -> true | _ -> false) -> unify_min ctx el
+		| WithType.WithType(t,_) ->
 			List.iter (fun e -> unify ctx e.etype t e.epos) el;
 			t
 	in
@@ -1920,7 +1920,7 @@ and type_map_declaration ctx e1 el with_type p =
 			| _ -> mk_mono(),mk_mono(),false
 		in
 		match with_type with
-		| WithType t -> get_map_params t
+		| WithType.WithType(t,_) -> get_map_params t
 		| _ -> (mk_mono(),mk_mono(),false)
 	in
 	let keys = Hashtbl.create 0 in
@@ -1939,19 +1939,19 @@ and type_map_declaration ctx e1 el with_type p =
 	) el in
 	let el_k,el_v,tkey,tval = if has_type then begin
 		let el_k,el_v = List.fold_left (fun (el_k,el_v) (e1,e2) ->
-			let e1 = type_expr ctx e1 (WithType tkey) in
+			let e1 = type_expr ctx e1 (WithType.with_type tkey) in
 			check_key e1;
 			let e1 = AbstractCast.cast_or_unify ctx tkey e1 e1.epos in
-			let e2 = type_expr ctx e2 (WithType tval) in
+			let e2 = type_expr ctx e2 (WithType.with_type tval) in
 			let e2 = AbstractCast.cast_or_unify ctx tval e2 e2.epos in
 			(e1 :: el_k,e2 :: el_v)
 		) ([],[]) el_kv in
 		el_k,el_v,tkey,tval
 	end else begin
 		let el_k,el_v = List.fold_left (fun (el_k,el_v) (e1,e2) ->
-			let e1 = type_expr ctx e1 Value in
+			let e1 = type_expr ctx e1 WithType.value in
 			check_key e1;
-			let e2 = type_expr ctx e2 Value in
+			let e2 = type_expr ctx e2 WithType.value in
 			(e1 :: el_k,e2 :: el_v)
 		) ([],[]) el_kv in
 		let unify_min_resume el = try
@@ -1983,7 +1983,7 @@ and type_local_function ctx name f with_type p =
 	let params = TypeloadFunction.type_function_params ctx f (match name with None -> "localfun" | Some (n,_) -> n) p in
 	if params <> [] then begin
 		if name = None then display_error ctx "Type parameters not supported in unnamed local functions" p;
-		if with_type <> NoValue then error "Type parameters are not supported for rvalue functions" p
+		if with_type <> WithType.NoValue then error "Type parameters are not supported for rvalue functions" p
 	end;
 	List.iter (fun tp -> if tp.tp_constraints <> None then display_error ctx "Type parameter constraints are not supported for local functions" p) f.f_params;
 	let inline,v,pname = (match name with
@@ -2001,7 +2001,7 @@ and type_local_function ctx name f with_type p =
 		s, c, t
 	) f.f_args in
 	(match with_type with
-	| WithType t ->
+	| WithType.WithType(t,_) ->
 		let rec loop t =
 			(match follow t with
 			| TFun (args2,tr) when List.length args2 = List.length args ->
@@ -2021,7 +2021,7 @@ and type_local_function ctx name f with_type p =
 			| _ -> ())
 		in
 		loop t
-	| NoValue ->
+	| WithType.NoValue ->
 		if name = None then display_error ctx "Unnamed lvalue functions are not supported" p
 	| _ ->
 		());
@@ -2073,11 +2073,11 @@ and type_local_function ctx name f with_type p =
 		else
 			mk (TVar (v,Some e)) ctx.t.tvoid p
 		) in
-		if with_type <> NoValue && not inline then mk (TBlock [decl;mk (TLocal v) v.v_type p]) v.v_type p else decl)
+		if with_type <> WithType.NoValue && not inline then mk (TBlock [decl;mk (TLocal v) v.v_type p]) v.v_type p else decl)
 
 and type_array_decl ctx el with_type p =
 	let tp = (match with_type with
-	| WithType t ->
+	| WithType.WithType(t,_) ->
 		let rec loop seen t =
 			(match follow t with
 			| TInst ({ cl_path = [],"Array" },[tp]) ->
@@ -2102,7 +2102,7 @@ and type_array_decl ctx el with_type p =
 	) in
 	(match tp with
 	| None ->
-		let el = List.map (fun e -> type_expr ctx e Value) el in
+		let el = List.map (fun e -> type_expr ctx e WithType.value) el in
 		let t = try
 			unify_min_raise ctx.com.basic el
 		with Error (Unify l,p) ->
@@ -2114,7 +2114,7 @@ and type_array_decl ctx el with_type p =
 		mk (TArrayDecl el) (ctx.t.tarray t) p
 	| Some t ->
 		let el = List.map (fun e ->
-			let e = type_expr ctx e (WithType t) in
+			let e = type_expr ctx e (WithType.with_type t) in
 			AbstractCast.cast_or_unify ctx t e p;
 		) el in
 		mk (TArrayDecl el) (ctx.t.tarray t) p)
@@ -2143,7 +2143,7 @@ and type_array_comprehension ctx e with_type p =
 	let e = map_compr e in
 	let ea = type_expr ctx !et with_type in
 	unify ctx v.v_type ea.etype p;
-	let efor = type_expr ctx e NoValue in
+	let efor = type_expr ctx e WithType.NoValue in
 	mk (TBlock [
 		mk (TVar (v,Some ea)) ctx.t.tvoid p;
 		efor;
@@ -2158,7 +2158,7 @@ and type_return ctx e p =
 		mk (TReturn None) t_dynamic p
 	| Some e ->
 		try
-			let e = type_expr ctx e (WithType ctx.ret) in
+			let e = type_expr ctx e (WithType.with_type ctx.ret) in
 			let e = AbstractCast.cast_or_unify ctx ctx.ret e p in
 			begin match follow e.etype with
 			| TAbstract({a_path=[],"Void"},_) ->
@@ -2206,10 +2206,10 @@ and type_cast ctx e t p =
 			error "Cast type must be a class or an enum" p
 	in
 	let texpr = loop t in
-	mk (TCast (type_expr ctx e Value,Some texpr)) t p
+	mk (TCast (type_expr ctx e WithType.value,Some texpr)) t p
 
 and type_if ctx e e1 e2 with_type p =
-	let e = type_expr ctx e Value in
+	let e = type_expr ctx e WithType.value in
 	let e = AbstractCast.cast_or_unify ctx ctx.t.tbool e p in
 	let e1 = type_expr ctx (Expr.ensure_block e1) with_type in
 	(match e2 with
@@ -2218,10 +2218,10 @@ and type_if ctx e e1 e2 with_type p =
 	| Some e2 ->
 		let e2 = type_expr ctx (Expr.ensure_block e2) with_type in
 		let e1,e2,t = match with_type with
-			| NoValue -> e1,e2,ctx.t.tvoid
-			| Value -> e1,e2,unify_min ctx [e1; e2]
-			| WithType t when (match follow t with TMono _ -> true | _ -> false) -> e1,e2,unify_min ctx [e1; e2]
-			| WithType t ->
+			| WithType.NoValue -> e1,e2,ctx.t.tvoid
+			| WithType.Value _ -> e1,e2,unify_min ctx [e1; e2]
+			| WithType.WithType(t,_) when (match follow t with TMono _ -> true | _ -> false) -> e1,e2,unify_min ctx [e1; e2]
+			| WithType.WithType(t,_) ->
 				let e1 = AbstractCast.cast_or_unify ctx t e1 e1.epos in
 				let e2 = AbstractCast.cast_or_unify ctx t e2 e2.epos in
 				e1,e2,t
@@ -2272,7 +2272,7 @@ and type_meta ctx m e1 with_type p =
 	ctx.meta <- old;
 	e
 
-and type_call ctx e el (with_type:with_type) p =
+and type_call ctx e el (with_type:WithType.t) p =
 	let def () =
 		let e = maybe_type_against_enum ctx (fun () -> type_access ctx (fst e) (snd e) MCall) with_type true p in
 		let e = build_call ctx e el with_type p in
@@ -2287,8 +2287,8 @@ and type_call ctx e el (with_type:with_type) p =
 		let params = (match el with [] -> [] | _ -> [("customParams",null_pos,NoQuotes),(EArrayDecl (List.map mk_to_string_meta el) , p)]) in
 		let infos = mk_infos ctx p params in
 		if (platform ctx.com Js || platform ctx.com Python) && el = [] && has_dce ctx.com then
-			let e = type_expr ctx e Value in
-			let infos = type_expr ctx infos Value in
+			let e = type_expr ctx e WithType.value in
+			let infos = type_expr ctx infos WithType.value in
 			let e = match follow e.etype with
 				| TAbstract({a_impl = Some c},_) when PMap.mem "toString" c.cl_statics ->
 					call_to_string ctx e
@@ -2298,31 +2298,31 @@ and type_call ctx e el (with_type:with_type) p =
 			let e_trace = mk (TIdent "`trace") t_dynamic p in
 			mk (TCall (e_trace,[e;infos])) ctx.t.tvoid p
 		else
-			type_expr ctx (ECall ((EField ((EField ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[mk_to_string_meta e;infos]),p) NoValue
+			type_expr ctx (ECall ((EField ((EField ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[mk_to_string_meta e;infos]),p) WithType.NoValue
 	| (EField ((EConst (Ident "super"),_),_),_), _ ->
 		def()
 	| (EField (e,"bind"),p), args ->
-		let e = type_expr ctx e Value in
+		let e = type_expr ctx e WithType.value in
 		(match follow e.etype with
 			| TFun signature -> type_bind ctx e signature args p
 			| _ -> def ())
 	| (EConst (Ident "$type"),_) , [e] ->
-		let e = type_expr ctx e Value in
+		let e = type_expr ctx e WithType.value in
 		ctx.com.warning (s_type (print_context()) e.etype) e.epos;
 		let e = Diagnostics.secure_generated_code ctx e in
 		e
 	| (EField(e,"match"),p), [epat] ->
-		let et = type_expr ctx e Value in
+		let et = type_expr ctx e WithType.value in
 		(match follow et.etype with
 			| TEnum _ ->
-				let e = Matcher.Match.match_expr ctx e [[epat],None,Some (EConst(Ident "true"),p),p] (Some (Some (EConst(Ident "false"),p),p)) (WithType ctx.t.tbool) p in
+				let e = Matcher.Match.match_expr ctx e [[epat],None,Some (EConst(Ident "true"),p),p] (Some (Some (EConst(Ident "false"),p),p)) (WithType.with_type ctx.t.tbool) p in
 				(* TODO: add that back *)
 (* 				let locals = !get_pattern_locals_ref ctx epat t in
 				PMap.iter (fun _ (_,p) -> display_error ctx "Capture variables are not allowed" p) locals; *)
 				e
 			| _ -> def ())
 	| (EConst (Ident "__unprotect__"),_) , [(EConst (String _),_) as e] ->
-		let e = type_expr ctx e Value in
+		let e = type_expr ctx e WithType.value in
 		if Common.platform ctx.com Flash then
 			let t = tfun [e.etype] e.etype in
 			let e_unprotect = mk (TIdent "__unprotect__") t p in
@@ -2351,7 +2351,7 @@ and type_call ctx e el (with_type:with_type) p =
 	| _ ->
 		def ()
 
-and type_expr ctx (e,p) (with_type:with_type) =
+and type_expr ctx (e,p) (with_type:WithType.t) =
 	match e with
 	| EField ((EConst (String s),ps),"code") ->
 		if UTF8.length s <> 1 then error "String must be a single UTF8 char" ps;
@@ -2359,7 +2359,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| EField(_,n) when starts_with n '$' ->
 		error "Field names starting with $ are not allowed" p
 	| EConst (Ident s) ->
-		if s = "super" && with_type <> NoValue && not ctx.in_display then error "Cannot use super as value" p;
+		if s = "super" && with_type <> WithType.NoValue && not ctx.in_display then error "Cannot use super as value" p;
 		let e = maybe_type_against_enum ctx (fun () -> type_ident ctx s p MGet) with_type false p in
 		acc_get ctx e p
 	| EField _
@@ -2376,7 +2376,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		Texpr.type_constant ctx.com.basic c p
 	| EBinop (op,e1,e2) ->
 		type_binop ctx op e1 e2 false with_type p
-	| EBlock [] when with_type <> NoValue ->
+	| EBlock [] when with_type <> WithType.NoValue ->
 		type_expr ctx (EObjectDecl [],p) with_type
 	| EBlock l ->
 		let locals = save_locals ctx in
@@ -2404,18 +2404,18 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		type_if ctx e e1 e2 with_type p
 	| EWhile (cond,e,NormalWhile) ->
 		let old_loop = ctx.in_loop in
-		let cond = type_expr ctx cond Value in
+		let cond = type_expr ctx cond WithType.value in
 		let cond = AbstractCast.cast_or_unify ctx ctx.t.tbool cond p in
 		ctx.in_loop <- true;
-		let e = type_expr ctx (Expr.ensure_block e) NoValue in
+		let e = type_expr ctx (Expr.ensure_block e) WithType.NoValue in
 		ctx.in_loop <- old_loop;
 		mk (TWhile (cond,e,NormalWhile)) ctx.t.tvoid p
 	| EWhile (cond,e,DoWhile) ->
 		let old_loop = ctx.in_loop in
 		ctx.in_loop <- true;
-		let e = type_expr ctx (Expr.ensure_block e) NoValue in
+		let e = type_expr ctx (Expr.ensure_block e) WithType.NoValue in
 		ctx.in_loop <- old_loop;
-		let cond = type_expr ctx cond Value in
+		let cond = type_expr ctx cond WithType.value in
 		let cond = AbstractCast.cast_or_unify ctx ctx.t.tbool cond cond.epos in
 		mk (TWhile (cond,e,DoWhile)) ctx.t.tvoid p
 	| ESwitch (e1,cases,def) ->
@@ -2435,7 +2435,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 	| ETry (e1,catches) ->
 		type_try ctx e1 catches with_type p
 	| EThrow e ->
-		let e = type_expr ctx e Value in
+		let e = type_expr ctx e WithType.value in
 		mk (TThrow e) (mk_mono()) p
 	| ECall (e,el) ->
 		type_call ctx e el with_type p
@@ -2457,7 +2457,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			epos = e.epos;
 		}
 	| ECast (e,None) ->
-		let e = type_expr ctx e Value in
+		let e = type_expr ctx e WithType.value in
 		mk (TCast (e,None)) (mk_mono()) p
 	| ECast (e, Some t) ->
 		type_cast ctx e t p
@@ -2467,7 +2467,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		assert false
 	| ECheckType (e,t) ->
 		let t = Typeload.load_complex_type ctx true t in
-		let e = type_expr ctx e (WithType t) in
+		let e = type_expr ctx e (WithType.with_type t) in
 		let e = AbstractCast.cast_or_unify ctx t e p in
 		if e.etype == t then e else mk (TCast (e,None)) t p
 	| EMeta (m,e1) ->
@@ -2594,7 +2594,7 @@ let rec create com =
 	(match m.m_types with
 	| [TClassDecl c1;TClassDecl c2] -> ctx.g.global_using <- (c1,c1.cl_pos) :: (c2,c2.cl_pos) :: ctx.g.global_using
 	| [TClassDecl c1] ->
-		let m = TypeloadModule.load_module ctx (["haxe"],"EnumValueTools") null_pos in
+		let m = TypeloadModule.load_module ctx (["haxe"],"EnumWithType.valueTools") null_pos in
 		(match m.m_types with
 		| [TClassDecl c2 ] -> ctx.g.global_using <- (c1,c1.cl_pos) :: (c2,c2.cl_pos) :: ctx.g.global_using
 		| _ -> assert false);

+ 1 - 1
src/typing/typerBase.ml

@@ -24,7 +24,7 @@ type object_decl_kind =
 	| ODKWithClass of tclass * tparams
 	| ODKPlain
 
-let build_call_ref : (typer -> access_kind -> expr list -> with_type -> pos -> texpr) ref = ref (fun _ _ _ _ _ -> assert false)
+let build_call_ref : (typer -> access_kind -> expr list -> WithType.t -> pos -> texpr) ref = ref (fun _ _ _ _ _ -> assert false)
 
 let relative_path ctx file =
 	let slashes path = String.concat "/" (ExtString.String.nsplit path "\\") in

+ 12 - 12
src/typing/typerDisplay.ml

@@ -24,7 +24,7 @@ let convert_function_signature ctx values (args,ret) = match DisplayEmitter.comp
 let completion_item_of_expr ctx e =
 	let retype e s t =
 		try
-			let e' = type_expr ctx (EConst(Ident s),null_pos) (WithType t) in
+			let e' = type_expr ctx (EConst(Ident s),null_pos) (WithType.with_type t) in
 			Texpr.equal e e'
 		with _ ->
 			false
@@ -132,7 +132,7 @@ let completion_item_of_expr ctx e =
 
 let get_expected_type ctx with_type =
 	let t = match with_type with
-		| WithType t -> Some t
+		| WithType.WithType(t,_) -> Some t
 		| _ -> None
 	in
 	match t with
@@ -204,14 +204,14 @@ let rec handle_signature_display ctx e_ast with_type =
 	match fst e_ast with
 		| ECall(e1,el) ->
 			let def () = try
-				type_expr ctx e1 Value
+				type_expr ctx e1 WithType.value
 			with Error (Unknown_ident "trace",_) ->
 				let e = expr_of_type_path (["haxe";"Log"],"trace") p in
-				type_expr ctx e Value
+				type_expr ctx e WithType.value
 			in
 			let e1 = match e1 with
 				| (EField (e,"bind"),p) ->
-					let e = type_expr ctx e Value in
+					let e = type_expr ctx e WithType.value in
 					(match follow e.etype with
 						| TFun signature -> e
 						| _ -> def ())
@@ -249,7 +249,7 @@ and display_expr ctx e_ast e dk with_type p =
 		handle_signature_display ctx e_ast with_type
 	| DMHover ->
 		let item = completion_item_of_expr ctx e in
-		raise_hover item e.epos
+		raise_hover item (Some with_type) e.epos
 	| DMUsage _ ->
 		let rec loop e = match e.eexpr with
 		| TField(_,FEnum(_,ef)) ->
@@ -398,7 +398,7 @@ let handle_display ctx e_ast dk with_type =
 			raise_signatures [(convert_function_signature ctx PMap.empty (arg,mono),doc)] 0 0
 		| _ ->
 			let t = TFun(arg,mono) in
-			raise_hover (make_ci_expr (mk (TIdent "trace") t (pos e_ast)) (tpair t)) (pos e_ast);
+			raise_hover (make_ci_expr (mk (TIdent "trace") t (pos e_ast)) (tpair t)) (Some (WithType.named_argument "expression")) (pos e_ast);
 		end
 	| (EConst (Ident "trace"),_),_ ->
 		let doc = Some "Print given arguments" in
@@ -409,9 +409,9 @@ let handle_display ctx e_ast dk with_type =
 			raise_signatures [(convert_function_signature ctx PMap.empty (arg,ret),doc)] 0 0
 		| _ ->
 			let t = TFun(arg,ret) in
-			raise_hover (make_ci_expr (mk (TIdent "trace") t (pos e_ast)) (tpair t)) (pos e_ast);
+			raise_hover (make_ci_expr (mk (TIdent "trace") t (pos e_ast)) (tpair t)) (Some (WithType.named_argument "value")) (pos e_ast);
 		end
-	| (EConst (Ident "_"),p),WithType t ->
+	| (EConst (Ident "_"),p),WithType.WithType(t,_) ->
 		mk (TConst TNull) t p (* This is "probably" a bind skip, let's just use the expected type *)
 	| (_,p),_ -> try
 		type_expr ctx e_ast with_type
@@ -464,12 +464,12 @@ let handle_display ctx e_ast dk with_type =
 	in
 	let is_display_debug = Meta.has (Meta.Custom ":debug.display") ctx.curfield.cf_meta in
 	if is_display_debug then begin
-		print_endline (Printf.sprintf "expected type: %s" (s_with_type with_type));
+		print_endline (Printf.sprintf "expected type: %s" (WithType.to_string with_type));
 		print_endline (Printf.sprintf "typed expr:\n%s" (s_expr_ast true "" (s_type (print_context())) e));
 	end;
 	let p = e.epos in
 	begin match with_type with
-		| WithType t ->
+		| WithType.WithType(t,_) ->
 			(* We don't want to actually use the transformed expression which may have inserted implicit cast calls.
 			   It only matters that unification takes place. *)
 			(try ignore(AbstractCast.cast_or_unify_raise ctx t e e.epos) with Error (Unify l,p) -> ());
@@ -488,7 +488,7 @@ let handle_edisplay ctx e dk with_type =
 	| DKCall,(DMSignature | DMDefault) -> handle_signature_display ctx e with_type
 	| DKStructure,DMDefault ->
 		begin match with_type with
-			| WithType t ->
+			| WithType.WithType(t,_) ->
 				begin match follow t with
 					| TAnon an ->
 						let origin = match t with