Quellcode durchsuchen

[eval] avoid uncaught exception stack duplication (closes #9286)

Aleksandr Kuzmenko vor 5 Jahren
Ursprung
Commit
83c23933ec

+ 11 - 7
src/macro/eval/evalExceptions.ml

@@ -95,14 +95,18 @@ let uncaught_exception_string v p extra =
 	(Printf.sprintf "%s : Uncaught exception %s%s" (format_pos p) (value_string v) extra)
 
 let get_exc_error_message ctx v stack p =
-	let pl = List.map (fun env -> {pfile = rev_hash env.env_info.pfile;pmin = env.env_leave_pmin; pmax = env.env_leave_pmax}) stack in
-	let pl = List.filter (fun p -> p <> null_pos) pl in
-	match pl with
-	| [] ->
+	if is v key_haxe_Exception then
 		uncaught_exception_string v p ""
-	| _ ->
-		let sstack = String.concat "\n" (List.map (fun p -> Printf.sprintf "%s : Called from here" (format_pos p)) pl) in
-		Printf.sprintf "%sUncaught exception %s\n%s" (if p = null_pos then "" else format_pos p ^ " : ") (value_string v) sstack
+	else begin
+		let pl = List.map (fun env -> {pfile = rev_hash env.env_info.pfile;pmin = env.env_leave_pmin; pmax = env.env_leave_pmax}) stack in
+		let pl = List.filter (fun p -> p <> null_pos) pl in
+		match pl with
+		| [] ->
+			uncaught_exception_string v p ""
+		| _ ->
+			let sstack = String.concat "\n" (List.map (fun p -> Printf.sprintf "%s : Called from here" (format_pos p)) pl) in
+			Printf.sprintf "%sUncaught exception %s\n%s" (if p = null_pos then "" else format_pos p ^ " : ") (value_string v) sstack
+	end
 
 let build_exception_stack ctx env =
 	let eval = env.env_eval in

+ 1 - 0
src/macro/eval/evalHash.ml

@@ -82,6 +82,7 @@ let key_haxe_macro_Unsafe = hash "haxe.macro.Unsafe"
 let key_sys_io__Process_NativeProcess = hash "sys.io._Process.NativeProcess"
 let key_sys_io_FileOutput = hash "sys.io.FileOutput"
 let key_sys_io_FileInput = hash "sys.io.FileInput"
+let key_haxe_Exception = hash "haxe.Exception"
 let key_haxe_io_Eof = hash "haxe.io.Eof"
 let key_haxe_macro_ExprDef = hash "haxe.macro.ExprDef"
 let key_haxe_macro_Binop = hash "haxe.macro.Binop"

+ 13 - 0
tests/misc/projects/Issue9286/Main.hx

@@ -0,0 +1,13 @@
+class Main {
+	public static function level2():Void {
+		level3();
+	}
+
+	public static function level3():Void {
+		throw "!";
+	}
+
+	static public function main() {
+		level2();
+	}
+}

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

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

+ 4 - 0
tests/misc/projects/Issue9286/compile-fail.hxml.stderr

@@ -0,0 +1,4 @@
+Main.hx:7: characters 3-8 : Uncaught exception Exception: !
+Called from Main.level3 (Main.hx line 7 column 3)
+Called from Main.level2 (Main.hx line 3 column 3)
+Called from Main.main (Main.hx line 11 column 3)