Bläddra i källkod

make haxe.rtti.Generic typing lazy (fix for self-recursion)

Nicolas Cannasse 15 år sedan
förälder
incheckning
15322ffad0
4 ändrade filer med 26 tillägg och 12 borttagningar
  1. 14 1
      codegen.ml
  2. 1 0
      doc/CHANGES.txt
  3. 10 0
      typecore.ml
  4. 1 11
      typeload.ml

+ 14 - 1
codegen.ml

@@ -254,7 +254,20 @@ let extend_xml_proxy ctx c t file p =
 let build_instance ctx mtype p =
 	match mtype with
 	| TClassDecl c ->
-		c.cl_types , c.cl_path , (match c.cl_kind with KGeneric -> build_generic ctx c p | _ -> (fun t -> TInst (c,t)))
+		let ft = (fun pl ->
+			match c.cl_kind with 
+			| KGeneric ->
+				let r = exc_protect (fun r ->
+					let t = mk_mono() in
+					r := (fun() -> t);	
+					unify_raise ctx (build_generic ctx c p pl) t p;
+					t
+				) in
+				TLazy r
+			| _ ->
+				TInst (c,pl)
+		) in
+		c.cl_types , c.cl_path , ft
 	| TEnumDecl e ->
 		e.e_types , e.e_path , (fun t -> TEnum (e,t))
 	| TTypeDecl t ->

+ 1 - 0
doc/CHANGES.txt

@@ -7,6 +7,7 @@
 	as3 : minor fixes in genas3 and --gen-hx-classes
 	as3 : fix with readonly/writeonly properties accesses
 	flash9 : list native getter/setters in Type API class/instance fields
+	all : make haxe.rtti.Generic typing lazy (fix for self-recursion)
 
 2010-01-09: 2.05
 	js : added js.Scroll

+ 10 - 0
typecore.ml

@@ -119,6 +119,16 @@ let unify_raise ctx t1 t2 p =
 			(* no untyped check *)
 			raise (Error (Unify l,p))
 
+let exc_protect f =
+	let rec r = ref (fun() ->
+		try
+			f r
+		with
+			| Error (Protect _,_) as e -> raise e
+			| Error (m,p) -> raise (Error (Protect m,p))
+	) in
+	r
+
 let save_locals ctx =
 	let locals = ctx.locals in
 	let map = ctx.locals_map in

+ 1 - 11
typeload.ml

@@ -43,16 +43,6 @@ let type_function_param ctx t e opt p =
 	| Some e ->
 		t, Some e
 
-let exc_protect f =
-	let rec r = ref (fun() ->
-		try
-			f r
-		with
-			| Error (Protect _,_) as e -> raise e
-			| Error (m,p) -> raise (Error (Protect m,p))
-	) in
-	r
-
 let type_static_var ctx t e p =
 	ctx.in_static <- true;
 	let e = type_expr ctx e true in
@@ -847,7 +837,7 @@ let type_module ctx m tdecls loadp =
 			Not_found ->
 				Hashtbl.add ctx.types_module tpath m;
 				tpath
-	in
+	in	
 	List.iter (fun (d,p) ->
 		match d with
 		| EImport _ | EUsing _ -> ()