Browse Source

[java/cs] Added legacy mode to overloads, when declared in the platform-neutral @:overload(function() {}) way.
fixed issue #1773

Caue Waneck 12 năm trước cách đây
mục cha
commit
5a552c24ca
1 tập tin đã thay đổi với 9 bổ sung12 xóa
  1. 9 12
      typer.ml

+ 9 - 12
typer.ml

@@ -458,18 +458,18 @@ let unify_min ctx el =
 let rec unify_call_params ctx ?(overloads=None) cf el args r p inline =
 let rec unify_call_params ctx ?(overloads=None) cf el args r p inline =
   (* 'overloads' will carry a ( return_result ) list, called 'compatible' *)
   (* 'overloads' will carry a ( return_result ) list, called 'compatible' *)
   (* it's used to correctly support an overload selection algorithm *)
   (* it's used to correctly support an overload selection algorithm *)
-	let overloads, compatible = match cf, overloads with
+	let overloads, compatible, legacy = match cf, overloads with
 		| Some(TInst(c,pl),f), None when ctx.com.config.pf_overload && Meta.has Meta.Overload f.cf_meta ->
 		| Some(TInst(c,pl),f), None when ctx.com.config.pf_overload && Meta.has Meta.Overload f.cf_meta ->
 				let overloads = List.filter (fun (_,f2) -> not (f == f2)) (Typeload.get_overloads c f.cf_name) in
 				let overloads = List.filter (fun (_,f2) -> not (f == f2)) (Typeload.get_overloads c f.cf_name) in
 				if overloads = [] then (* is static function *)
 				if overloads = [] then (* is static function *)
-					List.map (fun f -> f.cf_type, f) f.cf_overloads, []
+					List.map (fun f -> f.cf_type, f) f.cf_overloads, [], false
 				else
 				else
-					overloads, []
+					overloads, [], false
 		| Some(_,f), None ->
 		| Some(_,f), None ->
-				List.map (fun f -> f.cf_type, f) f.cf_overloads, []
+				List.map (fun f -> f.cf_type, f) f.cf_overloads, [], true
 		| _, Some s ->
 		| _, Some s ->
 				s
 				s
-		| _ -> [], []
+		| _ -> [], [], true
 	in
 	in
 	let next ?retval () =
 	let next ?retval () =
 		let compatible = Option.map_default (fun r -> r :: compatible) compatible retval in
 		let compatible = Option.map_default (fun r -> r :: compatible) compatible retval in
@@ -478,19 +478,16 @@ let rec unify_call_params ctx ?(overloads=None) cf el args r p inline =
 			let o = { o with cf_type = ft } in
 			let o = { o with cf_type = ft } in
 			let args, ret = (match follow (apply_params c.cl_types pl (field_type ctx c pl o p)) with (* I'm getting non-followed types here. Should it happen? *)
 			let args, ret = (match follow (apply_params c.cl_types pl (field_type ctx c pl o p)) with (* I'm getting non-followed types here. Should it happen? *)
 				| TFun (tl,t) -> tl, t
 				| TFun (tl,t) -> tl, t
-				| _ ->
-            print_endline (s_type (print_context()) o.cf_type);
-						print_endline o.cf_pos.pfile;
-            assert false
+				| _ -> assert false
 			) in
 			) in
-			Some (unify_call_params ctx ~overloads:(Some (l,compatible)) (Some (TInst(c,pl),o)) el args ret p inline)
+			Some (unify_call_params ctx ~overloads:(Some (l,compatible,legacy)) (Some (TInst(c,pl),o)) el args ret p inline)
 		| Some (t,_), (ft,o) :: l ->
 		| Some (t,_), (ft,o) :: l ->
 			let o = { o with cf_type = ft } in
 			let o = { o with cf_type = ft } in
 			let args, ret = (match Type.field_type o with
 			let args, ret = (match Type.field_type o with
 				| TFun (tl,t) -> tl, t
 				| TFun (tl,t) -> tl, t
 				| _ -> assert false
 				| _ -> assert false
 			) in
 			) in
-			Some (unify_call_params ctx ~overloads:(Some (l,compatible)) (Some (t, o)) el args ret p inline)
+			Some (unify_call_params ctx ~overloads:(Some (l,compatible,legacy)) (Some (t, o)) el args ret p inline)
 		| _ ->
 		| _ ->
 			match compatible with
 			match compatible with
 			| [] -> None
 			| [] -> None
@@ -544,7 +541,7 @@ let rec unify_call_params ctx ?(overloads=None) cf el args r p inline =
 			else
 			else
 				List.rev (acc), (TFun(args,r))
 				List.rev (acc), (TFun(args,r))
 			in
 			in
-			if ctx.com.config.pf_overload then
+			if not legacy && ctx.com.config.pf_overload then
 				match next ~retval:(args,tf) () with
 				match next ~retval:(args,tf) () with
 				| Some l -> l
 				| Some l -> l
 				| None ->
 				| None ->