|
@@ -5961,6 +5961,12 @@ struct
|
|
true)
|
|
true)
|
|
| _ -> true
|
|
| _ -> true
|
|
|
|
|
|
|
|
+ let unifies tfrom tto = try
|
|
|
|
+ unify tfrom tto;
|
|
|
|
+ true
|
|
|
|
+ with | _ ->
|
|
|
|
+ false
|
|
|
|
+
|
|
let do_unsafe_cast gen from_t to_t e =
|
|
let do_unsafe_cast gen from_t to_t e =
|
|
let t_path t =
|
|
let t_path t =
|
|
match t with
|
|
match t with
|
|
@@ -5971,25 +5977,29 @@ struct
|
|
| TDynamic _ -> ([], "Dynamic")
|
|
| TDynamic _ -> ([], "Dynamic")
|
|
| _ -> raise Not_found
|
|
| _ -> raise Not_found
|
|
in
|
|
in
|
|
- let do_default () =
|
|
|
|
- gen.gon_unsafe_cast to_t e.etype e.epos;
|
|
|
|
|
|
+ match gen.gfollow#run_f from_t, gen.gfollow#run_f to_t with
|
|
|
|
+ | TInst({ cl_kind = KTypeParameter tl },_), t2 when List.exists (fun t -> unifies t t2) tl ->
|
|
mk_cast to_t (mk_cast t_dynamic e)
|
|
mk_cast to_t (mk_cast t_dynamic e)
|
|
- in
|
|
|
|
- (* TODO: there really should be a better way to write that *)
|
|
|
|
- try
|
|
|
|
- if (Hashtbl.find gen.gsupported_conversions (t_path from_t)) from_t to_t then
|
|
|
|
- mk_cast to_t e
|
|
|
|
- else
|
|
|
|
- do_default()
|
|
|
|
- with
|
|
|
|
- | Not_found ->
|
|
|
|
- try
|
|
|
|
- if (Hashtbl.find gen.gsupported_conversions (t_path to_t)) from_t to_t then
|
|
|
|
- mk_cast to_t e
|
|
|
|
- else
|
|
|
|
- do_default()
|
|
|
|
- with
|
|
|
|
- | Not_found -> do_default()
|
|
|
|
|
|
+ | _ ->
|
|
|
|
+ let do_default () =
|
|
|
|
+ gen.gon_unsafe_cast to_t e.etype e.epos;
|
|
|
|
+ mk_cast to_t (mk_cast t_dynamic e)
|
|
|
|
+ in
|
|
|
|
+ (* TODO: there really should be a better way to write that *)
|
|
|
|
+ try
|
|
|
|
+ if (Hashtbl.find gen.gsupported_conversions (t_path from_t)) from_t to_t then
|
|
|
|
+ mk_cast to_t e
|
|
|
|
+ else
|
|
|
|
+ do_default()
|
|
|
|
+ with
|
|
|
|
+ | Not_found ->
|
|
|
|
+ try
|
|
|
|
+ if (Hashtbl.find gen.gsupported_conversions (t_path to_t)) from_t to_t then
|
|
|
|
+ mk_cast to_t e
|
|
|
|
+ else
|
|
|
|
+ do_default()
|
|
|
|
+ with
|
|
|
|
+ | Not_found -> do_default()
|
|
|
|
|
|
(* ****************************** *)
|
|
(* ****************************** *)
|
|
(* cast handler *)
|
|
(* cast handler *)
|