Ver Fonte

[eval] fix position parsing of haxe.macro.Error in non-macro context (closes #9390)

Aleksandr Kuzmenko há 5 anos atrás
pai
commit
8bd1bacc60

+ 18 - 2
src/macro/eval/evalExceptions.ml

@@ -146,8 +146,24 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
 			let v2 = field v key_pos in
 			GlobalState.get_ctx_ref := prev;
 			final();
-			match v1,v2 with
-				| VString s,VInstance {ikind = IPos p} ->
+			match v1 with
+				| VString s ->
+					let p =
+						match v2 with
+						| VInstance { ikind = IPos p } -> p
+						| VObject o ->
+							(try
+								let fields = object_fields o in
+								let min = match List.assoc key_min fields with VInt32 i -> Int32.to_int i | _ -> raise Not_found
+								and max = match List.assoc key_max fields with VInt32 i -> Int32.to_int i | _ -> raise Not_found
+								and file = match List.assoc key_file fields with VString s -> s.sstring | _ -> raise Not_found
+								in
+								{ pmin = min; pmax = max; pfile = file }
+							with Not_found ->
+								null_pos
+							)
+						| _ -> null_pos
+					in
 					raise (Error.Error (Error.Custom s.sstring,p))
 				| _ ->
 					Error.error "Something went wrong" null_pos

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

@@ -38,6 +38,9 @@ let key_hasNext = hash "hasNext"
 let key___meta__ = hash "__meta__"
 let key_get = hash "get"
 let key_pos = hash "pos"
+let key_min = hash "min"
+let key_max = hash "max"
+let key_file = hash "file"
 let key_len = hash "len"
 let key_message = hash "message"
 let key_exception_message = hash "__exceptionMessage"

+ 5 - 0
tests/misc/projects/Issue9390/Main.hx

@@ -0,0 +1,5 @@
+class Main {
+	static function main() {
+		throw new haxe.macro.Expr.Error("hi", (macro _).pos);
+	}
+}

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

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

+ 1 - 0
tests/misc/projects/Issue9390/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:3: characters 48-49 : hi