Browse Source

[net-lib] Generally improved error and debug messages;
Consider explicit interface implementations when adding interface
methods;
(typeload) Do not check overrides on classes added by -net-lib;
(typeload) Do not throw an error if a variable was previously declared
by an explicit interface

Cauê Waneck 10 years ago
parent
commit
482dda90bd
3 changed files with 35 additions and 5 deletions
  1. 8 3
      gencs.ml
  2. 1 1
      std/cs/_std/Array.hx
  3. 26 1
      typeload.ml

+ 8 - 3
gencs.ml

@@ -3397,6 +3397,8 @@ let convert_ilmethod ctx p m is_explicit_impl =
 			APrivate
 		| FAPublic -> APublic
 		| _ ->
+			if PMap.mem "net_loader_debug" ctx.ncom.defines then
+				Printf.printf "\tmethod %s (skipped) : %s\n" cff_name (IlMetaDebug.ilsig_s m.msig.ssig);
 			raise Exit
 	in
 	let is_static = ref false in
@@ -3721,8 +3723,11 @@ let convert_ilclass ctx p ?(delegate=false) ilcls = match ilcls.csuper with
 	| _ ->
 		let flags = ref [HExtern] in
 		(* todo: instead of CsNative, use more specific definitions *)
-		if PMap.mem "net_loader_debug" ctx.ncom.defines then
-			print_endline ("converting " ^ ilpath_s ilcls.cpath);
+		if PMap.mem "net_loader_debug" ctx.ncom.defines then begin
+			let sup = match ilcls.csuper with | None -> [] | Some c -> [IlMetaDebug.ilsig_s c.ssig] in
+			let sup = sup @ List.map (fun i -> IlMetaDebug.ilsig_s i.ssig) ilcls.cimplements in
+			print_endline ("converting " ^ ilpath_s ilcls.cpath ^ " : " ^ (String.concat ", " sup))
+		end;
 		let meta = ref [Meta.CsNative, [], p; Meta.Native, [EConst (String (ilpath_s ilcls.cpath) ), p], p] in
 
 		let is_interface = ref false in
@@ -4022,7 +4027,7 @@ let normalize_ilcls ctx cls =
 				| (f,_,name,false) as ff ->
 					(* look for compatible fields *)
 					if not (List.exists (function
-						| (f2,_,name2,false) when name = name2 ->
+						| (f2,_,name2,false) when (name = name2 || String.ends_with name2 ("." ^ name)) -> (* consider explicit implementations as implementations *)
 							compatible_field f f2
 						| _ -> false
 					) !current_all) then begin

+ 1 - 1
std/cs/_std/Array.hx

@@ -99,7 +99,7 @@ import cs.NativeArray;
 		{
 			return -1;
 		}
-		return cs.system.Array._IndexOf(__a, x, i, len - i);
+		return cs.system.Array.IndexOf(__a, x, i, len - i);
 	}
 
 	public function lastIndexOf( x : T, ?fromIndex:Int ) : Int

+ 26 - 1
typeload.ml

@@ -836,6 +836,7 @@ let check_overriding ctx c =
 		| [] -> ()
 		| i :: _ ->
 			display_error ctx ("Field " ^ i.cf_name ^ " is declared 'override' but doesn't override any field") i.cf_pos)
+	| _ when c.cl_extern && Meta.has Meta.CsNative c.cl_meta -> () (* -net-lib specific: do not check overrides on extern CsNative classes *)
 	| Some (csup,params) ->
 		PMap.iter (fun i f ->
 			let p = f.cf_pos in
@@ -1725,6 +1726,24 @@ let init_class ctx c p context_init herits fields =
 			PMap.exists f c.cl_fields || has_field f c.cl_super || List.exists (fun i -> has_field f (Some i)) c.cl_implements
 	in
 
+	let rec get_declared f = function
+		| None -> None
+		| Some (c,a) when PMap.exists f c.cl_fields ->
+			Some (c,a)
+		| Some (c,_) ->
+			let ret = get_declared f c.cl_super in
+			match ret with
+				| Some r -> Some r
+				| None ->
+					let rec loop ifaces = match ifaces with
+						| [] -> None
+						| i :: ifaces -> match get_declared f (Some i) with
+							| Some r -> Some r
+							| None -> loop ifaces
+					in
+					loop c.cl_implements
+	in
+
 	(match c.cl_super with None -> () | Some _ -> delay ctx PForce (fun() -> check_overriding ctx c));
 	if ctx.com.config.pf_overload then delay ctx PForce (fun() -> check_overloads ctx c);
 
@@ -1779,7 +1798,13 @@ let init_class ctx c p context_init herits fields =
 
 	let bind_var ctx cf e stat inline =
 		let p = cf.cf_pos in
-		if not stat && has_field cf.cf_name c.cl_super then error ("Redefinition of variable " ^ cf.cf_name ^ " in subclass is not allowed") p;
+		if not stat then begin match get_declared cf.cf_name c.cl_super with
+				| None -> ()
+				| Some (csup,_) ->
+					(* this can happen on -net-lib generated classes if a combination of explicit interfaces and variables with the same name happens *)
+					if not (csup.cl_interface && Meta.has Meta.CsNative c.cl_meta) then
+						error ("Redefinition of variable " ^ cf.cf_name ^ " in subclass is not allowed. Previously declared at " ^ (Ast.s_type_path csup.cl_path) ) p
+		end;
 		let t = cf.cf_type in
 
 		match e with