2
0
Simon Krajewski 13 жил өмнө
parent
commit
b5e649e51b
2 өөрчлөгдсөн 11 нэмэгдсэн , 0 устгасан
  1. 4 0
      interp.ml
  2. 7 0
      std/haxe/macro/Context.hx

+ 4 - 0
interp.ml

@@ -2176,6 +2176,10 @@ let macro_lib =
 			try	encode_complex_type (make_complex_type (decode_type v))
 			with Exit -> VNull
 		);
+		"unify", Fun2 (fun t1 t2 ->
+			try Type.unify (decode_type t1) (decode_type t2); VBool true
+			with Unify_error _ -> VBool false
+		);
 		"typeof", Fun1 (fun v ->
 			encode_type ((get_ctx()).curapi.typeof (decode_expr v))
 		);

+ 7 - 0
std/haxe/macro/Context.hx

@@ -185,6 +185,13 @@ class Context {
 		return load("to_complex", 1)(t);
 	}
 	
+	/**
+		Returns true if t1 and t2 unify, false otherwise
+	**/
+	public static function unify( t1 : Type, t2 : Type) : Bool {
+		return load("unify", 2)(t1, t2);
+	}
+	
 	/**
 		Follow all typedefs to reach the actual real type
 	**/