Ver código fonte

[python] don't wrap classes that inherit from BaseException in _HxException

Dan Korostelev 11 anos atrás
pai
commit
8582bf9452
1 arquivos alterados com 13 adições e 1 exclusões
  1. 13 1
      genpy.ml

+ 13 - 1
genpy.ml

@@ -1300,7 +1300,19 @@ module Printer = struct
 			| TContinue ->
 				"continue"
 			| TThrow e1 ->
-				Printf.sprintf "raise _HxException(%s)" (print_expr pctx e1)
+				let rec is_native_exception t =
+					match Abstract.follow_with_abstracts t with
+					| TInst ({ cl_path = [],"BaseException" }, _) ->
+						true
+					| TInst ({ cl_super = Some csup }, _) ->
+						is_native_exception (TInst(fst csup, snd csup))
+					| _ ->
+						false
+				in
+				if is_native_exception e1.etype then
+					Printf.sprintf "raise %s" (print_expr pctx e1)
+				else
+					Printf.sprintf "raise _HxException(%s)" (print_expr pctx e1)
 			| TCast(e1,None) ->
 				print_expr pctx e1
 			| TMeta((Meta.Custom ":ternaryIf",_,_),{eexpr = TIf(econd,eif,Some eelse)}) ->