Rudy Ges 6 месяцев назад
Родитель
Сommit
aef8f2c19e

+ 26 - 0
tests/server/src/cases/issues/Issue12001.hx

@@ -15,6 +15,19 @@ class Issue12001 extends TestCase {
 		assertSuccess();
 	}
 
+	function testRedefineTypeCatchError(_) {
+		vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
+		vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
+		var args = ["-main", "Empty", "--macro", "Macro.redefineTypeCatchError()"];
+		runHaxe(args);
+		assertSuccess();
+
+		runHaxe(args);
+		assertSuccess();
+		assertHasPrint("Macro.hx:56: TInst(Foobar,[])");
+		assertHasPrint("Macro.hx:69: Cannot redefine module Foobar");
+	}
+
 	@:async
 	@:timeout(3000)
 	function testRedefineType(async:Async) {
@@ -46,6 +59,19 @@ class Issue12001 extends TestCase {
 		assertSuccess();
 	}
 
+	function testRedefineModuleCatchError(_) {
+		vfs.putContent("Macro.hx", getTemplate("issues/Issue12001/Macro.hx"));
+		vfs.putContent("Empty.hx", getTemplate("Empty.hx"));
+		var args = ["-main", "Empty", "--macro", "Macro.redefineModuleCatchError()"];
+		runHaxe(args);
+		assertSuccess();
+
+		runHaxe(args);
+		assertSuccess();
+		assertHasPrint("Macro.hx:77: TInst(Foobaz,[])");
+		assertHasPrint("Macro.hx:90: Cannot redefine module Foobaz");
+	}
+
 	@:async
 	@:timeout(3000)
 	function testRedefineModule(async:Async) {

+ 43 - 0
tests/server/test/templates/issues/Issue12001/Macro.hx

@@ -1,4 +1,5 @@
 import haxe.macro.Context;
+import haxe.macro.Expr.Error;
 
 @:persistent var i = 0;
 function defineType() {
@@ -48,3 +49,45 @@ function hookRedefine() {
 		}]);
 	});
 }
+
+@:persistent var l = 0;
+function redefineTypeCatchError() {
+	Context.onAfterInitMacros(() -> {
+		if (l > 0) trace(Context.getType("Foobar"));
+
+		try {
+			l++;
+			Context.defineType({
+				pos: Context.currentPos(),
+				pack: [],
+				name: "Foobar",
+				kind: TDClass(null, null, false, false, false),
+				fields: []
+			});
+		} catch (e:Error) {
+			if (l == 0) throw e;
+			trace(e.message);
+		}
+	});
+}
+
+@:persistent var m = 0;
+function redefineModuleCatchError() {
+	Context.onAfterInitMacros(() -> {
+		if (m > 0) trace(Context.getType("Foobaz"));
+
+		try {
+			m++;
+			Context.defineModule("Foobaz", [{
+				pos: Context.currentPos(),
+				pack: [],
+				name: "Foobaz",
+				kind: TDClass(null, null, false, false, false),
+				fields: []
+			}]);
+		} catch (e:Error) {
+			if (m == 0) throw e;
+			trace(e.message);
+		}
+	});
+}

+ 3 - 2
tests/server/test/templates/issues/Issue12001/Macro1.hx

@@ -1,5 +1,6 @@
 import haxe.macro.CompilationServer;
 import haxe.macro.Context;
+import haxe.macro.Expr.Error;
 
 function hookInvalidateError() {
 	Context.onAfterTyping((_) -> {
@@ -11,8 +12,8 @@ function hookInvalidateCatch() {
 	Context.onAfterTyping((_) -> {
 		try {
 			CompilationServer.invalidateModule("Empty");
-		} catch (e:Dynamic) {
-			Sys.println(Std.string(e));
+		} catch (e:Error) {
+			Sys.println(e.message);
 		}
 	});
 }