diff --git a/interp.ml b/interp.ml index 04e7b39e61d..46338375188 100644 --- a/interp.ml +++ b/interp.ml @@ -123,6 +123,7 @@ type extern_api = { delayed_macro : int -> (unit -> (unit -> value)); use_cache : unit -> bool; format_string : string -> Ast.pos -> Ast.expr; + cast_or_unify : Type.t -> texpr -> Ast.pos -> Type.texpr; } type callstack = { @@ -2344,8 +2345,9 @@ let macro_lib = with Exit -> VNull ); "unify", Fun2 (fun t1 t2 -> - try Type.unify (decode_type t1) (decode_type t2); VBool true - with Unify_error _ -> VBool false + let e1 = mk (TConst TNull) (decode_type t1) Ast.null_pos in + try ignore(((get_ctx()).curapi.cast_or_unify) (decode_type t2) e1 Ast.null_pos); VBool true + with Typecore.Error (Typecore.Unify _,_) -> VBool false ); "typeof", Fun1 (fun v -> encode_type ((get_ctx()).curapi.type_expr (decode_expr v)).etype diff --git a/typer.ml b/typer.ml index f37816364f7..590418a3bec 100644 --- a/typer.ml +++ b/typer.ml @@ -4387,6 +4387,9 @@ let make_macro_api ctx p = Interp.format_string = (fun s p -> format_string ctx s p ); + Interp.cast_or_unify = (fun t e p -> + Codegen.AbstractCast.cast_or_unify_raise ctx t e p + ); } let rec init_macro_interp ctx mctx mint =