Browse Source

MacroApi.type_expr vs diagnostics (#11048)

* [tests] add test for #6794

* Ignore diagnostics mode when using MacroApi.type_expr
Rudy Ges 2 years ago
parent
commit
4fb03d4845

+ 2 - 0
src/typing/macroContext.ml

@@ -84,6 +84,7 @@ let macro_timer ctx l =
 let typing_timer ctx need_type f =
 let typing_timer ctx need_type f =
 	let t = Timer.timer ["typing"] in
 	let t = Timer.timer ["typing"] in
 	let old = ctx.com.error and oldp = ctx.pass and oldlocals = ctx.locals in
 	let old = ctx.com.error and oldp = ctx.pass and oldlocals = ctx.locals in
+	let restore_report_mode = disable_report_mode ctx.com in
 	(*
 	(*
 		disable resumable errors... unless we are in display mode (we want to reach point of completion)
 		disable resumable errors... unless we are in display mode (we want to reach point of completion)
 	*)
 	*)
@@ -98,6 +99,7 @@ let typing_timer ctx need_type f =
 		ctx.com.error <- old;
 		ctx.com.error <- old;
 		ctx.pass <- oldp;
 		ctx.pass <- oldp;
 		ctx.locals <- oldlocals;
 		ctx.locals <- oldlocals;
+		restore_report_mode ();
 	in
 	in
 	try
 	try
 		let r = f() in
 		let r = f() in

+ 17 - 0
tests/misc/projects/Issue6794/Main.hx

@@ -0,0 +1,17 @@
+#if macro
+import haxe.macro.Expr;
+import haxe.macro.Context;
+#end
+
+class Main {
+	#if !macro
+	static function main()
+		test();
+	#end
+
+	static macro function test() {
+		try Context.typeof(macro foo)
+		catch (e) Context.warning("foo", (macro 0).pos);
+		return macro {};
+	}
+}

+ 2 - 0
tests/misc/projects/Issue6794/compile.hxml

@@ -0,0 +1,2 @@
+--main Main
+--display "Main.hx@0@diagnostics"

+ 1 - 0
tests/misc/projects/Issue6794/compile.hxml.stderr

@@ -0,0 +1 @@
+[{"file":"$$normPath(::cwd::/,true)Main.hx","diagnostics":[{"kind":2,"severity":2,"range":{"start":{"line":13,"character":42},"end":{"line":13,"character":43}},"args":"foo"}]}]