From 9aa99113b3b0d71ce8df321b4a6dfdeef8fa682b Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 15 Oct 2024 08:30:29 +0200 Subject: [PATCH] fail nicer if we can't find a macro function see #11776 --- src/macro/eval/evalStdLib.ml | 7 +++++-- tests/misc/projects/Issue11776/Main.hx | 10 ++++++++++ tests/misc/projects/Issue11776/compile-fail.hxml | 2 ++ .../misc/projects/Issue11776/compile-fail.hxml.stderr | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/misc/projects/Issue11776/Main.hx create mode 100644 tests/misc/projects/Issue11776/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11776/compile-fail.hxml.stderr diff --git a/src/macro/eval/evalStdLib.ml b/src/macro/eval/evalStdLib.ml index 70c56b5597a..1191c9976cd 100644 --- a/src/macro/eval/evalStdLib.ml +++ b/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 diff --git a/tests/misc/projects/Issue11776/Main.hx b/tests/misc/projects/Issue11776/Main.hx new file mode 100644 index 00000000000..ce8957136a3 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/tests/misc/projects/Issue11776/compile-fail.hxml b/tests/misc/projects/Issue11776/compile-fail.hxml new file mode 100644 index 00000000000..b30a755894b --- /dev/null +++ b/tests/misc/projects/Issue11776/compile-fail.hxml @@ -0,0 +1,2 @@ +--main Main +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11776/compile-fail.hxml.stderr b/tests/misc/projects/Issue11776/compile-fail.hxml.stderr new file mode 100644 index 00000000000..c9d6764cd7c --- /dev/null +++ b/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 \ No newline at end of file