Browse Source

retain tvar identity in macro encoding (see #3917)

Simon Krajewski 10 years ago
parent
commit
5be4f8d4dc
2 changed files with 9 additions and 16 deletions
  1. 4 11
      interp.ml
  2. 5 5
      std/haxe/macro/Type.hx

+ 4 - 11
interp.ml

@@ -4602,6 +4602,7 @@ and encode_tvar v =
 		"capture", VBool v.v_capture;
 		"extra", vopt f_extra v.v_extra;
 		"meta", encode_meta_content v.v_meta;
+		"$", VAbstract (AUnsafe (Obj.repr v));
 	]
 
 and encode_module_type mt =
@@ -4711,17 +4712,9 @@ let decode_type_params v =
 	List.map (fun v -> dec_string (field v "name"),decode_type (field v "t")) (dec_array v)
 
 let decode_tvar v =
-	let f_extra v =
-		decode_type_params (field v "params"),opt decode_texpr (field v "expr")
-	in
-	{
-		v_id = (match (field v "id") with VInt i -> i | _ -> raise Invalid_expr);
-		v_name = dec_string (field v "name");
-		v_type = decode_type (field v "t");
-		v_capture = dec_bool (field v "capture");
-		v_extra = opt f_extra (field v "extra");
-		v_meta = decode_meta_content (field v "meta")
-	}
+	match field v "$" with
+	| VAbstract (AUnsafe t) -> Obj.obj t
+	| _ -> raise Invalid_expr
 
 let decode_var_access v =
 	match decode_enum v with

+ 5 - 5
std/haxe/macro/Type.hx

@@ -279,11 +279,11 @@ enum TConstant {
 }
 
 typedef TVar = {
-	id: Int,
-	name: String,
-	t: Type,
-	capture: Bool,
-	extra: Null<{params: Array<TypeParameter>, expr: Null<TypedExpr>}>
+	public var id(default, never):Int;
+	public var name(default, never):String;
+	public var t(default, never):Type;
+	public var capture(default, never):Bool;
+	public var extra(default,never):Null<{params: Array<TypeParameter>, expr: Null<TypedExpr>}>;
 }
 
 enum ModuleType {