Skip to content

Commit

Permalink
[eval] catch Invalid_expr when handling an API call
Browse files Browse the repository at this point in the history
closes #7007
  • Loading branch information
Simn committed Jun 5, 2018
1 parent 2bc777a commit dfe1795
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/macro/eval/evalMain.ml
Expand Up @@ -341,7 +341,15 @@ let setup get_api =
let api = get_api (fun() -> (get_ctx()).curapi.get_com()) (fun() -> (get_ctx()).curapi) in
List.iter (fun (n,v) -> match v with
| VFunction(f,b) ->
let v = VFunction ((fun vl -> try f vl with Sys_error msg | Failure msg -> exc_string msg),b) in
let f vl = try
f vl
with
| Sys_error msg | Failure msg ->
exc_string msg
| MacroApi.Invalid_expr ->
exc_string "Invalid expression"
in
let v = VFunction (f,b) in
Hashtbl.replace EvalStdLib.macro_lib n v
| _ -> assert false
) api;
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/src/unit/issues/Issue7007.hx
@@ -0,0 +1,18 @@
package unit.issues;

class Issue7007 extends unit.Test {
function test() {
#if !macro
eq("Exception caught: Invalid expression", catchMe());
#end
}

macro static function catchMe() {
try {
trace(haxe.macro.Context.getTypedExpr(null));
} catch (e:Dynamic) {
return macro $v{'Exception caught: $e'};
}
return macro null;
}
}

0 comments on commit dfe1795

Please sign in to comment.