Prechádzať zdrojové kódy

fail nicer if we can't find a macro function

see #11776
Simon Krajewski 1 rok pred
rodič
commit
9aa99113b3

+ 5 - 2
src/macro/eval/evalStdLib.ml

@@ -613,9 +613,12 @@ module StdContext = struct
 		else raise (EvalDebugMisc.BreakHere)
 	)
 
-	let callMacroApi = vfun1 (fun f ->
+	let callMacroApi = vfun1 (fun f  ->
 		let f = decode_string f in
-		Hashtbl.find GlobalState.macro_lib f
+		try
+			Hashtbl.find GlobalState.macro_lib f
+		with Not_found ->
+			exc_string ("Could not find macro function \"" ^ f ^ "\"")
 	)
 
 	let plugins = ref PMap.empty

+ 10 - 0
tests/misc/projects/Issue11776/Main.hx

@@ -0,0 +1,10 @@
+class Main {
+	static function main() {
+		breakEverything();
+	}
+
+	static macro function breakEverything() {
+		eval.vm.Context.callMacroApi("oh no");
+		return macro null;
+	}
+}

+ 2 - 0
tests/misc/projects/Issue11776/compile-fail.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp

+ 3 - 0
tests/misc/projects/Issue11776/compile-fail.hxml.stderr

@@ -0,0 +1,3 @@
+Main.hx:3: characters 3-20 : Uncaught exception Could not find macro function "oh no"
+Main.hx:7: characters 3-40 : Called from here
+Main.hx:3: characters 3-20 : Called from here