Browse Source

[java/cs] Fixed many "No overload found for this constructor call"

- Fixed how super arguments are typed when creating empty ctor. Closes
- Fixed the unify argument order. Closes #3961
Cauê Waneck 10 years ago
parent
commit
2b9fb237fd
2 changed files with 15 additions and 10 deletions
  1. 14 10
      gencommon.ml
  2. 1 0
      std/java/_std/Type.hx

+ 14 - 10
gencommon.ml

@@ -1692,10 +1692,11 @@ struct
 	let rec prev_ctor c tl =
 	let rec prev_ctor c tl =
 		match c.cl_super with
 		match c.cl_super with
 		| None -> raise Not_found
 		| None -> raise Not_found
-		| Some (sup,stl) -> let stl = List.map (apply_params c.cl_params tl) stl in
-		match sup.cl_constructor with
-		| None -> prev_ctor sup stl
-		| Some ctor -> ctor, sup, stl
+		| Some (sup,stl) ->
+			let stl = List.map (apply_params c.cl_params tl) stl in
+			match sup.cl_constructor with
+			| None -> prev_ctor sup stl
+			| Some ctor -> ctor, sup, stl
 
 
 	(* replaces super() call with last static constructor call *)
 	(* replaces super() call with last static constructor call *)
 	let replace_super_call gen name c tl with_params me p =
 	let replace_super_call gen name c tl with_params me p =
@@ -2016,10 +2017,10 @@ struct
 							in
 							in
 							let args,_ = get_fun sctor.cf_type in
 							let args,_ = get_fun sctor.cf_type in
 							let best = loop sctor.cf_overloads (sctor, List.length args) in
 							let best = loop sctor.cf_overloads (sctor, List.length args) in
-							let args,_ = get_fun best.cf_type in
+							let args,_ = get_fun (apply_params sup.cl_params stl best.cf_type) in
 							[{
 							[{
 								eexpr = TCall(
 								eexpr = TCall(
-									{ eexpr = TConst TSuper; etype = TInst(cl, List.map snd cl.cl_params); epos = cl.cl_pos },
+									{ eexpr = TConst TSuper; etype = TInst(sup, stl); epos = cl.cl_pos },
 									List.map (fun (n,o,t) -> null t cl.cl_pos) args);
 									List.map (fun (n,o,t) -> null t cl.cl_pos) args);
 								etype = basic.tvoid;
 								etype = basic.tvoid;
 								epos = cl.cl_pos
 								epos = cl.cl_pos
@@ -6265,7 +6266,8 @@ struct
 			let is_empty_call = Type.type_iseq t empty_t in
 			let is_empty_call = Type.type_iseq t empty_t in
 			let ret = List.filter (fun cf -> match follow cf.cf_type with
 			let ret = List.filter (fun cf -> match follow cf.cf_type with
 			(* | TFun([_,_,t],_) -> incr count; true *)
 			(* | TFun([_,_,t],_) -> incr count; true *)
-			| TFun([_,_,t],_) -> replace_mono t; incr count; is_empty_call = (Type.type_iseq t empty_t)
+			| TFun([_,_,t],_) ->
+				replace_mono t; incr count; is_empty_call = (Type.type_iseq t empty_t)
 			| _ -> false) ctors in
 			| _ -> false) ctors in
 			ret, !count > 1
 			ret, !count > 1
 		| _ ->
 		| _ ->
@@ -6278,12 +6280,13 @@ struct
 			| [], [] -> true
 			| [], [] -> true
 			| (_,_,t) :: arglist, et :: elist -> (try
 			| (_,_,t) :: arglist, et :: elist -> (try
 				let t = run_follow gen t in
 				let t = run_follow gen t in
-				unify et t;
+				unify t et;
 				check_arg arglist elist
 				check_arg arglist elist
 			with | Unify_error el ->
 			with | Unify_error el ->
 				(* List.iter (fun el -> gen.gcon.warning (Typecore.unify_error_msg (print_context()) el) p) el; *)
 				(* List.iter (fun el -> gen.gcon.warning (Typecore.unify_error_msg (print_context()) el) p) el; *)
 				false)
 				false)
-			| _ -> false
+			| _ ->
+				false
 		in
 		in
 		let rec check_cf cf =
 		let rec check_cf cf =
 			let t = apply_params sup.cl_params stl cf.cf_type in
 			let t = apply_params sup.cl_params stl cf.cf_type in
@@ -6573,7 +6576,8 @@ struct
 				(* the TNew and TSuper code was modified at r6497 *)
 				(* the TNew and TSuper code was modified at r6497 *)
 				| TCall( { eexpr = TConst TSuper } as ef, eparams ) ->
 				| TCall( { eexpr = TConst TSuper } as ef, eparams ) ->
 					let cl, tparams = match follow ef.etype with
 					let cl, tparams = match follow ef.etype with
-					| TInst(cl,p) -> cl, p
+					| TInst(cl,p) ->
+						cl,p
 					| _ -> assert false in
 					| _ -> assert false in
 					(try
 					(try
 						let is_overload, cf, sup, stl = choose_ctor gen cl tparams (List.map (fun e -> e.etype) eparams) maybe_empty_t e.epos in
 						let is_overload, cf, sup, stl = choose_ctor gen cl tparams (List.map (fun e -> e.etype) eparams) maybe_empty_t e.epos in

+ 1 - 0
std/java/_std/Type.hx

@@ -56,6 +56,7 @@ using StringTools;
 
 
 	public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic>
 	public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic>
 	{
 	{
+		var c = java.Lib.toNativeType(c);
 		var cl:java.lang.Class<Dynamic> = c == null ? null : untyped c.getSuperclass();
 		var cl:java.lang.Class<Dynamic> = c == null ? null : untyped c.getSuperclass();
 		if (cl != null && cl.getName() != "haxe.lang.HxObject" && cl.getName() != "java.lang.Object") {
 		if (cl != null && cl.getName() != "haxe.lang.HxObject" && cl.getName() != "java.lang.Object") {
 			return cast cl;
 			return cast cl;