Browse Source

lookup unqualified types in all package hierarchy and not only in current package

Nicolas Cannasse 14 years ago
parent
commit
3df1cb36e4
2 changed files with 12 additions and 4 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 11 4
      typeload.ml

+ 1 - 0
doc/CHANGES.txt

@@ -30,6 +30,7 @@
 	flash9 : added support for FP 10.1 and 10.2
 	flash9 : added @:meta(Meta(k="v")) support
 	all : improved #if support (fixed ! precedence)
+	all : lookup unqualified types in all package hierarchy and not only in current package
 
 2010-08-14: 2.06
 	neko : change serializer to be able to handle instances of basic classes from other modules

+ 11 - 4
typeload.ml

@@ -71,6 +71,15 @@ let rec load_type_def ctx p t =
 				with
 					Not_found -> raise (Error (Type_not_found (m.mpath,tname),p))
 			in
+			let rec loop = function
+				| [] -> raise Exit
+				| (_ :: lnext) as l ->
+					try
+						load_type_def ctx p { t with tpackage = List.rev l }
+					with
+						| Error (Module_not_found _,p2)
+						| Error (Type_not_found _,p2) when p == p2 -> loop lnext
+			in
 			try
 				if not no_pack then raise Exit;
 				(match fst ctx.current.mpath with
@@ -84,11 +93,9 @@ let rec load_type_def ctx p t =
 						| Forbidden -> raise Exit
 						| _ -> ())
 					with Not_found -> ());
-				load_type_def ctx p { t with tpackage = fst ctx.current.mpath }
+				loop (List.rev (fst ctx.current.mpath));
 			with
-				| Error (Module_not_found _,p2)
-				| Error (Type_not_found _,p2) when p == p2 -> next()
-				| Exit -> next()
+				Exit -> next()
 
 (* build an instance from a full type *)
 let rec load_instance ctx t p allow_no_params =