瀏覽代碼

Rework message context (from macro, from cache)

Also apply from_macro in some places it was missing (macro API)
Context.info() is now cache bound, like Context.warning()
When pulling info/warning from cache, append "(from cache)" to printed message
Rudy Ges 1 年之前
父節點
當前提交
df1854fb59

+ 5 - 5
src/compiler/compilationContext.ml

@@ -79,8 +79,8 @@ type server_api = {
 let message ctx msg =
 	ctx.messages <- msg :: ctx.messages
 
-let error ctx ?(depth=0) ?(from_macro = false) msg p =
-	message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Error)
+let error ctx ?(message_context:compiler_message_context = message_context ()) msg p =
+	message ctx (make_compiler_message ~message_context msg p DKCompilerMessage Error)
 
 let after_error ctx =
 	ctx.has_error <- true;
@@ -88,12 +88,12 @@ let after_error ctx =
 
 let error_ext ctx (err : Error.error) =
 	Error.recurse_error (fun depth err ->
-		error ~depth ~from_macro:err.err_from_macro ctx (Error.error_msg err.err_message) err.err_pos
+		error ~message_context:(message_context ~depth ~from_macro:err.err_from_macro ()) ctx (Error.error_msg err.err_message) err.err_pos
 	) err;
 	after_error ctx
 
-let error ctx ?(depth=0) ?(from_macro = false) msg p =
-	error ctx ~depth ~from_macro msg p;
+let error ?(message_context = message_context ()) ctx msg p =
+	error ~message_context ctx msg p;
 	after_error ctx
 
 let create_native_lib file extern kind = {

+ 5 - 5
src/compiler/compiler.ml

@@ -18,7 +18,7 @@ let run_or_diagnose ctx f =
 		| Error.Error err ->
 			ctx.has_error <- true;
 			Error.recurse_error (fun depth err ->
-				add_diagnostics_message ~depth com (Error.error_msg err.err_message) err.err_pos DKCompilerMessage Error
+				add_diagnostics_message ~message_context:(message_context ~depth ~from_macro:err.err_from_macro ()) com (Error.error_msg err.err_message) err.err_pos DKCompilerMessage Error
 			) err;
 			(match com.report_mode with
 			| RMLegacyDiagnostics _ -> DisplayOutput.emit_legacy_diagnostics ctx.com
@@ -236,10 +236,10 @@ module Setup = struct
 		Common.define_value com Define.Haxe s_version;
 		Common.raw_define com "true";
 		Common.define_value com Define.Dce "std";
-		com.info <- (fun ?(depth=0) ?(from_macro=false) msg p ->
-			message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Information)
+		com.info <- (fun ?(message_context=message_context ()) msg p ->
+			message ctx (make_compiler_message ~message_context msg p DKCompilerMessage Information)
 		);
-		com.warning <- (fun ?(depth=0) ?(from_macro=false) w options msg p ->
+		com.warning <- (fun ?(message_context=message_context ()) w options msg p ->
 			match Warning.get_mode w (com.warning_options @ options) with
 			| WMEnable ->
 				let wobj = Warning.warning_obj w in
@@ -248,7 +248,7 @@ module Setup = struct
 				else
 					Printf.sprintf "(%s) %s" wobj.w_name msg
 				in
-				message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Warning)
+				message ctx (make_compiler_message ~message_context msg p DKCompilerMessage Warning)
 			| WMDisable ->
 				()
 		);

+ 4 - 4
src/compiler/displayProcessing.ml

@@ -92,14 +92,14 @@ let process_display_arg ctx actx =
 let process_display_configuration ctx =
 	let com = ctx.com in
 	if is_diagnostics com then begin
-		com.info <- (fun ?depth ?from_macro s p ->
-			add_diagnostics_message ?depth com s p DKCompilerMessage Information
+		com.info <- (fun ?message_context s p ->
+			add_diagnostics_message ?message_context com s p DKCompilerMessage Information
 		);
-		com.warning <- (fun ?(depth = 0) ?from_macro w options s p ->
+		com.warning <- (fun ?(message_context = message_context ()) w options s p ->
 			match Warning.get_mode w (com.warning_options @ options) with
 			| WMEnable ->
 				let wobj = Warning.warning_obj w in
-				add_diagnostics_message ~depth ~code:(Some wobj.w_name) com s p DKCompilerMessage Warning
+				add_diagnostics_message ~message_context ~code:(Some wobj.w_name) com s p DKCompilerMessage Warning
 			| WMDisable ->
 				()
 		);

+ 33 - 34
src/compiler/messageReporting.ml

@@ -88,7 +88,7 @@ let compiler_pretty_message_string com ectx cm =
 	(* Filter some messages that don't add much when using this message renderer *)
 	| "End of overload failure reasons" -> None
 	| _ -> begin
-		ectx.last_positions <- (IntMap.add cm.cm_depth cm.cm_pos ectx.last_positions);
+		ectx.last_positions <- (IntMap.add cm.cm_context.cm_depth cm.cm_pos ectx.last_positions);
 		let is_null_pos = cm.cm_pos = null_pos || cm.cm_pos.pmin = -1 in
 		let is_unknown_file f = f = "" || f = "?" in
 
@@ -130,8 +130,8 @@ let compiler_pretty_message_string com ectx cm =
 		in
 
 		let parent_pos =
-			if cm.cm_depth = 0 then null_pos
-			else (try IntMap.find (cm.cm_depth-1) ectx.last_positions with Not_found -> null_pos)
+			if cm.cm_context.cm_depth = 0 then null_pos
+			else (try IntMap.find (cm.cm_context.cm_depth-1) ectx.last_positions with Not_found -> null_pos)
 		in
 
 		let prev_pos,prev_sev,prev_nl = match ectx.previous with
@@ -140,23 +140,23 @@ let compiler_pretty_message_string com ectx cm =
 		in
 
 		let sev_changed = prev_sev = None || Some cm.cm_severity <> prev_sev in
-		let pos_changed = (prev_pos = None || cm.cm_pos <> Option.get prev_pos || (cm.cm_depth <> prev_nl && cm.cm_depth <> prev_nl + 1)) && (parent_pos = null_pos || cm.cm_pos <> parent_pos) in
+		let pos_changed = (prev_pos = None || cm.cm_pos <> Option.get prev_pos || (cm.cm_context.cm_depth <> prev_nl && cm.cm_context.cm_depth <> prev_nl + 1)) && (parent_pos = null_pos || cm.cm_pos <> parent_pos) in
 		let file_changed = prev_pos = None || (pos_changed && match (cm.cm_pos.pfile, (Option.get prev_pos).pfile) with
 			| (f1, f2) when (is_unknown_file f1) && (is_unknown_file f2) -> false
 			| (f1, f2) -> f1 <> f2
 		) in
 
-		let display_heading = cm.cm_depth = 0 || sev_changed || file_changed in
+		let display_heading = cm.cm_context.cm_depth = 0 || sev_changed || file_changed in
 		let has_source = match lines with | [] -> false | _ -> true in
-		let display_source = has_source && (cm.cm_depth = 0 || sev_changed || pos_changed) in
-		let display_pos_marker = (not is_null_pos) && has_source && (cm.cm_depth = 0 || sev_changed || pos_changed) in
+		let display_source = has_source && (cm.cm_context.cm_depth = 0 || sev_changed || pos_changed) in
+		let display_pos_marker = (not is_null_pos) && has_source && (cm.cm_context.cm_depth = 0 || sev_changed || pos_changed) in
 
-		let gutter_len = (try String.length (Printf.sprintf "%d" (IntMap.find cm.cm_depth ectx.max_lines)) with Not_found -> 0) + 2 in
+		let gutter_len = (try String.length (Printf.sprintf "%d" (IntMap.find cm.cm_context.cm_depth ectx.max_lines)) with Not_found -> 0) + 2 in
 
 		let no_color = Define.defined com.defines Define.MessageNoColor in
 		let c_reset = if no_color then "" else "\x1b[0m" in
-		let c_bold = if no_color then "" else "\x1b[1m" in
-		let c_dim = if no_color then "" else "\x1b[2m" in
+		let dim str = if no_color then str else "\x1b[2m" ^ str ^ c_reset in
+		let bold str = if no_color then str else "\x1b[1m" ^ str ^ c_reset in
 
 		let (c_sev, c_sev_bg) = if no_color then ("", "") else match cm.cm_severity with
 			| MessageSeverity.Warning -> ("\x1b[33m", "\x1b[30;43m")
@@ -164,7 +164,7 @@ let compiler_pretty_message_string com ectx cm =
 			| Error -> ("\x1b[31m", "\x1b[30;41m")
 		in
 
-		let sev_label = if cm.cm_depth > 0 then " -> " else Printf.sprintf
+		let sev_label = if cm.cm_context.cm_depth > 0 then " -> " else Printf.sprintf
 			(if no_color then "[%s]" else " %s ")
 			(match cm.cm_severity with
 				| MessageSeverity.Warning -> "WARNING"
@@ -180,7 +180,7 @@ let compiler_pretty_message_string com ectx cm =
 				(* Severity heading *)
 				(c_sev_bg ^ sev_label ^ c_reset ^ " ")
 				(* Macro context indicator *)
-				(if cm.cm_from_macro then c_sev ^ "(macro) " ^ c_reset else "")
+				(if cm.cm_context.cm_from_macro then c_sev ^ "(macro) " ^ c_reset else "")
 				(* File + line pointer *)
 				epos;
 
@@ -200,22 +200,19 @@ let compiler_pretty_message_string com ectx cm =
 				(* Source code at that line *)
 				(
 					if l = 0 then
-						c_dim ^ line ^ c_reset
+						dim line
 					else if l1 = l2 then
-						(if p1 > 1 then c_dim ^ (String.sub line 0 (p1-1)) else "")
-						^ c_reset ^ c_bold ^ (String.sub line (p1-1) (p2-p1))
-						^ c_reset ^ c_dim ^ (String.sub line (p2-1) (len - p2 + 1))
-						^ c_reset
+						(if p1 > 1 then dim (String.sub line 0 (p1-1)) else c_reset)
+						^ bold (String.sub line (p1-1) (p2-p1))
+						^ dim (String.sub line (p2-1) (len - p2 + 1))
 					else begin
 						(if (l = l1) then
-							(if p1 > 1 then c_dim ^ (String.sub line 0 (p1-1)) else "")
-							^ c_reset ^ c_bold ^ (String.sub line (p1-1) (len-p1+1))
-							^ c_reset
+							(if p1 > 1 then dim (String.sub line 0 (p1-1)) else c_reset)
+							^ bold (String.sub line (p1-1) (len-p1+1))
 						else if (l = l2) then
-							(if p2 > 1 then c_bold ^ (String.sub line 0 (p2-1)) else "")
-							^ c_reset ^ c_dim ^ (String.sub line (p2-1) (len-p2+1))
-							^ c_reset
-						else c_bold ^ line ^ c_reset)
+							(if p2 > 1 then bold (String.sub line 0 (p2-1)) else c_reset)
+							^ dim (String.sub line (p2-1) (len-p2+1))
+						else bold line)
 					end
 				)
 		) !out lines;
@@ -228,15 +225,17 @@ let compiler_pretty_message_string com ectx cm =
 				(if l1 = l2 then String.make p1 ' ' ^ c_sev ^ String.make (if p1 = p2 then 1 else p2-p1) '^' ^ c_reset else "");
 
 		(* Error message *)
+		(* TODO: only if some define is used? *)
+		let cm_message = if cm.cm_context.cm_from_cache then cm.cm_message ^ " " ^ (dim "(from cache)") else cm.cm_message in
 		out := List.fold_left (fun out str -> Printf.sprintf "%s%s| %s\n"
 			out
 			(String.make gutter_len ' ')
 			(* Remove "... " prefix *)
 			(if (ExtString.String.starts_with str "... ") then String.sub str 4 ((String.length str) - 4) else str)
-		) !out (ExtString.String.nsplit cm.cm_message "\n");
+		) !out (ExtString.String.nsplit cm_message "\n");
 
-		ectx.previous <- Some ((if is_null_pos then null_pos else cm.cm_pos), cm.cm_severity, cm.cm_depth);
-		ectx.gutter <- (IntMap.add cm.cm_depth gutter_len ectx.gutter);
+		ectx.previous <- Some ((if is_null_pos then null_pos else cm.cm_pos), cm.cm_severity, cm.cm_context.cm_depth);
+		ectx.gutter <- (IntMap.add cm.cm_context.cm_depth gutter_len ectx.gutter);
 
 		(* Indent sub errors *)
 		let rec indent ?(acc=0) depth =
@@ -245,9 +244,9 @@ let compiler_pretty_message_string com ectx cm =
 		in
 
 		Some (
-			if cm.cm_depth > 0 then String.concat "\n" (List.map (fun str -> match str with
+			if cm.cm_context.cm_depth > 0 then String.concat "\n" (List.map (fun str -> match str with
 				| "" -> ""
-				| _ -> (String.make (indent cm.cm_depth) ' ') ^ str
+				| _ -> (String.make (indent cm.cm_context.cm_depth) ' ') ^ str
 			) (ExtString.String.nsplit !out "\n"))
 			else !out
 		)
@@ -297,8 +296,8 @@ let compiler_indented_message_string ectx cm =
 			in
 			let lines =
 				match (ExtString.String.nsplit str "\n") with
-				| first :: rest -> (cm.cm_depth, first) :: List.map (fun msg -> (cm.cm_depth+1, msg)) rest
-				| l -> [(cm.cm_depth, List.hd l)]
+				| first :: rest -> (cm.cm_context.cm_depth, first) :: List.map (fun msg -> (cm.cm_context.cm_depth+1, msg)) rest
+				| l -> [(cm.cm_context.cm_depth, List.hd l)]
 			in
 			let rm_prefix str = if (ExtString.String.starts_with str "... ") then String.sub str 4 ((String.length str) - 4) else str in
 			Some (String.concat "\n" (List.map (fun (depth, msg) -> (String.make (depth*2) ' ') ^ epos ^ " : " ^ (rm_prefix msg)) lines))
@@ -307,16 +306,16 @@ let compiler_indented_message_string ectx cm =
 let get_max_line max_lines messages =
 	List.fold_left (fun max_lines cm ->
 		let _,_,l2,_ = Lexer.get_pos_coords cm.cm_pos in
-		let old = try IntMap.find cm.cm_depth max_lines with Not_found -> 0 in
+		let old = try IntMap.find cm.cm_context.cm_depth max_lines with Not_found -> 0 in
 
-		if l2 > old then IntMap.add cm.cm_depth l2 max_lines
+		if l2 > old then IntMap.add cm.cm_context.cm_depth l2 max_lines
 		else max_lines
 	) max_lines messages
 
 let display_source_at com p =
 	let absolute_positions = Define.defined com.defines Define.MessageAbsolutePositions in
 	let ectx = create_error_context absolute_positions in
-	let msg = make_compiler_message "" p 0 MessageKind.DKCompilerMessage MessageSeverity.Information in
+	let msg = make_compiler_message "" p MessageKind.DKCompilerMessage MessageSeverity.Information in
 	ectx.max_lines <- get_max_line ectx.max_lines [msg];
 	match compiler_pretty_message_string com ectx msg with
 		| None -> ()

+ 5 - 3
src/compiler/server.ml

@@ -32,7 +32,7 @@ let check_display_flush ctx f_otherwise = match ctx.com.json_out with
 	| _ ->
 		if is_diagnostics ctx.com then begin
 			List.iter (fun cm ->
-				add_diagnostics_message ~depth:cm.cm_depth ctx.com cm.cm_message cm.cm_pos cm.cm_kind cm.cm_severity
+				add_diagnostics_message ~message_context:cm.cm_context ctx.com cm.cm_message cm.cm_pos cm.cm_kind cm.cm_severity
 			) (List.rev ctx.messages);
 			(match ctx.com.report_mode with
 			| RMDiagnostics _ -> ()
@@ -478,8 +478,10 @@ let handle_cache_bound_objects com cbol =
 			Hashtbl.replace com.resources name data
 		| IncludeFile(file,position) ->
 			com.include_files <- (file,position) :: com.include_files
-		| Warning(w,msg,p) ->
-			com.warning w [] msg p
+		| Info(msg,p,ctx) ->
+			com.info ~message_context:{ ctx with cm_from_cache = true } msg p
+		| Warning(w,msg,p,ctx) ->
+			com.warning ~message_context:{ ctx with cm_from_cache = true } w [] msg p
 	) cbol
 
 (* Adds module [m] and all its dependencies (recursively) from the cache to the current compilation

+ 16 - 12
src/context/common.ml

@@ -371,8 +371,8 @@ type context = {
 	mutable print : string -> unit;
 	mutable error : ?depth:int -> string -> pos -> unit;
 	mutable error_ext : Error.error -> unit;
-	mutable info : ?depth:int -> ?from_macro:bool -> string -> pos -> unit;
-	mutable warning : ?depth:int -> ?from_macro:bool -> warning -> Warning.warning_option list list -> string -> pos -> unit;
+	mutable info : ?message_context:compiler_message_context -> string -> pos -> unit;
+	mutable warning : ?message_context:compiler_message_context -> warning -> Warning.warning_option list list -> string -> pos -> unit;
 	mutable warning_options : Warning.warning_option list list;
 	mutable get_messages : unit -> compiler_message list;
 	mutable filter_messages : (compiler_message -> bool) -> unit;
@@ -435,9 +435,13 @@ let ignore_error com =
 	if b then com.has_error <- true;
 	b
 
-let module_warning com m w options msg p =
-	if com.display.dms_full_typing then DynArray.add m.m_extra.m_cache_bound_objects (Warning(w,msg,p));
-	com.warning w options msg p
+let module_info ?(message_context:compiler_message_context = message_context ()) com m msg p =
+	if com.display.dms_full_typing then DynArray.add m.m_extra.m_cache_bound_objects (Info(msg,p,message_context));
+	com.info ~message_context msg p
+
+let module_warning ?(message_context:compiler_message_context = message_context ()) com m w options msg p =
+	if com.display.dms_full_typing then DynArray.add m.m_extra.m_cache_bound_objects (Warning(w,msg,p,message_context));
+	com.warning ~message_context w options msg p
 
 (* Defines *)
 
@@ -818,8 +822,8 @@ let create compilation_step cs version args display_mode =
 		user_defines = Hashtbl.create 0;
 		user_metas = Hashtbl.create 0;
 		get_macros = (fun() -> None);
-		info = (fun ?depth ?from_macro _ _ -> die "" __LOC__);
-		warning = (fun ?depth ?from_macro _ _ _ -> die "" __LOC__);
+		info = (fun ?message_context _ _ -> die "" __LOC__);
+		warning = (fun ?message_context _ _ _ -> die "" __LOC__);
 		warning_options = [];
 		error = (fun ?depth _ _ -> die "" __LOC__);
 		error_ext = (fun _ -> die "" __LOC__);
@@ -1170,21 +1174,21 @@ let utf16_to_utf8 str =
 	loop 0;
 	Buffer.contents b
 
-let add_diagnostics_message ?(depth = 0) ?(code = None) com s p kind sev =
+let add_diagnostics_message ?(message_context = message_context ()) ?(code = None) com s p kind sev =
 	if sev = MessageSeverity.Error then com.has_error <- true;
 	let di = com.shared.shared_display_information in
-	di.diagnostics_messages <- (make_diagnostic ~depth ~code s p kind sev) :: di.diagnostics_messages
+	di.diagnostics_messages <- (make_diagnostic ~message_context ~code s p kind sev) :: di.diagnostics_messages
 
 let display_error_ext com err =
 	if is_diagnostics com then begin
 		Error.recurse_error (fun depth err ->
-			add_diagnostics_message ~depth com (Error.error_msg err.err_message) err.err_pos MessageKind.DKCompilerMessage MessageSeverity.Error;
+			add_diagnostics_message ~message_context:(message_context ~depth ~from_macro:err.err_from_macro ()) com (Error.error_msg err.err_message) err.err_pos MessageKind.DKCompilerMessage MessageSeverity.Error;
 		) err;
 	end else
 		com.error_ext err
 
-let display_error com ?(depth = 0) msg p =
-	display_error_ext com (Error.make_error ~depth (Custom msg) p)
+let display_error com ?(message_context = message_context ()) msg p =
+	display_error_ext com (Error.make_error ~depth:message_context.cm_depth ~from_macro:message_context.cm_from_macro (Custom msg) p)
 
 let dump_path com =
 	Define.defined_value_safe ~default:"dump" com.defines Define.DumpPath

+ 3 - 3
src/context/typecore.ml

@@ -357,11 +357,11 @@ let type_generic_function_ref : (typer -> field_access -> (unit -> texpr) field_
 
 let create_context_ref : (Common.context -> ((unit -> unit) * typer) option -> typer) ref = ref (fun _ -> assert false)
 
-let warning ?(depth=0) ctx w msg p =
+let warning ?(message_context:compiler_message_context = message_context ()) ctx w msg p =
 	let options = (Warning.from_meta ctx.c.curclass.cl_meta) @ (Warning.from_meta ctx.f.curfield.cf_meta) in
 	match Warning.get_mode w options with
 	| WMEnable ->
-		module_warning ctx.com ctx.m.curmod w options msg p
+		module_warning ~message_context ctx.com ctx.m.curmod w options msg p
 	| WMDisable ->
 		()
 
@@ -438,7 +438,7 @@ let add_local ctx k n t p =
 				(* ignore std lib *)
 				if not (List.exists (fun path -> ExtLib.String.starts_with p.pfile (path#path)) ctx.com.class_paths#get_std_paths) then begin
 					warning ctx WVarShadow "This variable shadows a previously declared variable" p;
-					warning ~depth:1 ctx WVarShadow (compl_msg "Previous variable was here") v'.v_pos
+					warning ~message_context:(message_context ~depth:1 ()) ctx WVarShadow (compl_msg "Previous variable was here") v'.v_pos
 				end
 			with Not_found ->
 				()

+ 20 - 9
src/core/globals.ml

@@ -210,22 +210,32 @@ module MessageKind = struct
 		| DKMissingFields -> 7
 end
 
-type compiler_message = {
-	cm_message : string;
-	cm_pos : pos;
+type compiler_message_context = {
 	cm_depth : int;
 	cm_from_macro : bool;
+	cm_from_cache : bool;
+}
+
+let message_context ?(depth = 0) ?(from_macro = false) ?(from_cache=false) () = {
+	cm_depth = depth;
+	cm_from_macro = from_macro;
+	cm_from_cache = from_cache;
+}
+
+type compiler_message = {
+	cm_message : string;
 	cm_kind : MessageKind.t;
 	cm_severity : MessageSeverity.t;
+	cm_pos : pos; (* would be nice to have in cm_context but this makes a bit of a mess.. *)
+	cm_context : compiler_message_context;
 }
 
-let make_compiler_message ?(from_macro = false) msg p depth kind sev = {
+let make_compiler_message ?(message_context:compiler_message_context = message_context ()) msg p kind sev = {
 	cm_message = msg;
-	cm_pos = p;
-	cm_depth = depth;
-	cm_from_macro = from_macro;
 	cm_kind = kind;
 	cm_severity = sev;
+	cm_pos = p;
+	cm_context = message_context;
 }
 
 type diagnostic = {
@@ -237,13 +247,14 @@ type diagnostic = {
 	diag_depth : int;
 }
 
-let make_diagnostic ?(depth = 0) ?(code = None) message pos kind sev = {
+let make_diagnostic ?(message_context = message_context ()) ?(code = None) message pos kind sev = {
 	diag_message = message;
 	diag_pos = pos;
 	diag_code = code;
 	diag_kind = kind;
 	diag_severity = sev;
-	diag_depth = depth;
+	(* TODO: handle from_macro and from_cache *)
+	diag_depth = message_context.cm_depth;
 }
 
 let i32_31 = Int32.of_int 31

+ 2 - 1
src/core/tType.ml

@@ -59,7 +59,8 @@ type type_param_host =
 type cache_bound_object =
 	| Resource of string * string
 	| IncludeFile of string * string
-	| Warning of WarningList.warning * string * pos
+	| Info of string * pos * compiler_message_context
+	| Warning of WarningList.warning * string * pos * compiler_message_context
 
 type t =
 	| TMono of tmono

+ 1 - 1
src/macro/eval/evalLuv.ml

@@ -553,7 +553,7 @@ let uv_error_fields = [
 				| HaxeError.Error err ->
 						let messages = ref [] in
 						HaxeError.recurse_error (fun depth err ->
-							let cm = make_compiler_message ~from_macro:err.err_from_macro (HaxeError.error_msg err.err_message) err.err_pos depth DKCompilerMessage Error in
+							let cm = make_compiler_message ~message_context:(message_context ~depth:err.err_depth ~from_macro:err.err_from_macro ()) (HaxeError.error_msg err.err_message) err.err_pos DKCompilerMessage Error in
 							let ectx = MessageReporting.create_error_context false in
 							match MessageReporting.compiler_message_string ectx cm with
 								| None -> ()

+ 1 - 1
src/macro/eval/evalMain.ml

@@ -152,7 +152,7 @@ let create com api is_macro =
 				| Error.Error err ->
 						let messages = ref [] in
 						Error.recurse_error (fun depth err ->
-							messages := (make_compiler_message ~from_macro:err.err_from_macro (Error.error_msg err.err_message) err.err_pos depth DKCompilerMessage Error) :: !messages;
+							messages := (make_compiler_message ~message_context:(message_context ~depth:err.err_depth ~from_macro:err.err_from_macro ()) (Error.error_msg err.err_message) err.err_pos DKCompilerMessage Error) :: !messages;
 						) err;
 						MessageReporting.format_messages com !messages
 				| _ -> Printexc.to_string ex

+ 3 - 3
src/macro/macroApi.ml

@@ -64,7 +64,7 @@ type 'value compiler_api = {
 	flush_context : (unit -> t) -> t;
 	info : ?depth:int -> string -> pos -> unit;
 	warning : ?depth:int -> Warning.warning -> string -> pos -> unit;
-	display_error : ?depth:int -> (string -> pos -> unit);
+	display_error : ?message_context:compiler_message_context -> (string -> pos -> unit);
 	with_imports : 'a . import list -> placed_name list list -> (unit -> 'a) -> 'a;
 	with_options : 'a . compiler_options -> (unit -> 'a) -> 'a;
 	exc_string : 'a . string -> 'a;
@@ -1804,7 +1804,7 @@ let macro_api ccom get_api =
 			let msg = decode_string msg in
 			let p = decode_pos p in
 			let depth = decode_int depth in
-			(get_api()).display_error ~depth msg p;
+			(get_api()).display_error ~message_context:(message_context ~depth ()) msg p;
 			raise Abort
 		);
 		"fatal_error", vfun3 (fun msg p depth ->
@@ -1817,7 +1817,7 @@ let macro_api ccom get_api =
 			let msg = decode_string msg in
 			let p = decode_pos p in
 			let depth = decode_int depth in
-			(get_api()).display_error ~depth msg p;
+			(get_api()).display_error ~message_context:(message_context ~depth ()) msg p;
 			vnull
 		);
 		"warning", vfun3 (fun msg p depth ->

+ 10 - 7
src/typing/macroContext.ml

@@ -279,10 +279,10 @@ let make_macro_com_api com mcom p =
 			Interp.exc_string "unsupported"
 		);
 		info = (fun ?(depth=0) msg p ->
-			com.info ~depth msg p
+			com.info ~message_context:(message_context ~depth ~from_macro:true ()) msg p
 		);
 		warning = (fun ?(depth=0) w msg p ->
-			com.warning ~depth w [] msg p
+			com.warning ~message_context:(message_context ~depth ~from_macro:true ()) w [] msg p
 		);
 		exc_string = Interp.exc_string;
 		get_hxb_writer_config = (fun () ->
@@ -575,8 +575,11 @@ let make_macro_api ctx mctx p =
 			in
 			Std.finally restore f ()
 		);
+		MacroApi.info = (fun ?(depth=0) msg p ->
+			module_info ~message_context:(message_context ~depth ~from_macro:true ()) ctx.com ctx.m.curmod msg p
+		);
 		MacroApi.warning = (fun ?(depth=0) w msg p ->
-			warning ~depth ctx w msg p
+			warning ~message_context:(message_context ~depth ~from_macro:true ()) ctx w msg p
 		);
 	}
 
@@ -675,12 +678,12 @@ let create_macro_interp api mctx =
 		on_error { err with err_from_macro = true }
 	);
 	let on_warning = com2.warning in
-	com2.warning <- (fun ?(depth=0) ?(from_macro=false) w options msg p ->
-		on_warning ~depth ~from_macro:true w options msg p
+	com2.warning <- (fun ?(message_context=message_context ()) w options msg p ->
+		on_warning ~message_context:{message_context with cm_from_macro = true} w options msg p
 	);
 	let on_info = com2.info in
-	com2.info <- (fun ?(depth=0) ?(from_macro=false) msg p ->
-		on_info ~depth ~from_macro:true msg p
+	com2.info <- (fun ?(message_context=message_context ()) msg p ->
+		on_info ~message_context:{message_context with cm_from_macro = true} msg p
 	);
 	(* mctx.g.core_api <- ctx.g.core_api; // causes some issues because of optional args and Null type in Flash9 *)
 	init();