Selaa lähdekoodia

[inline] determine overloads again when inline-mapping calls to overloaded fields

see #7599
Simon Krajewski 5 vuotta sitten
vanhempi
commit
c62eb49134
3 muutettua tiedostoa jossa 24 lisäystä ja 16 poistoa
  1. 3 15
      src/generators/genjvm.ml
  2. 18 1
      src/optimization/inline.ml
  3. 3 0
      src/typing/callUnification.ml

+ 3 - 15
src/generators/genjvm.ml

@@ -1480,14 +1480,6 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 				Error.error (Printf.sprintf "Bad __array__ type: %s" (s_type (print_context()) tr)) e1.epos;
 			end
 		| TField(e1,FStatic(c,({cf_kind = Method (MethNormal | MethInline)} as cf))) ->
-			let c,cf = match cf.cf_overloads with
-				| [] -> c,cf
-				| _ -> match OverloadResolution.filter_overloads (OverloadResolution.find_overload (fun t -> t) c cf el) with
-					| None ->
-						Error.error "Could not find overload" e1.epos
-					| Some(c,cf,_) ->
-						c,cf
-			in
 			let tl,tr = self#call_arguments cf.cf_type el in
 			jm#invokestatic c.cl_path cf.cf_name (method_sig tl tr);
 			tr
@@ -1521,13 +1513,9 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 				self#texpr rvalue_any e1;
 				false
 			in
-			begin match OverloadResolution.maybe_resolve_instance_overload false (apply_params c.cl_params tl) c cf el with
-			| None -> Error.error "Could not find overload" e1.epos
-			| Some(c,cf,_) ->
-				let tl,tr = self#call_arguments cf.cf_type el in
-				(if is_super then jm#invokespecial else if (has_class_flag c CInterface) then jm#invokeinterface else jm#invokevirtual) c.cl_path cf.cf_name (self#vtype cf.cf_type);
-				tr
-			end
+			let tl,tr = self#call_arguments cf.cf_type el in
+			(if is_super then jm#invokespecial else if (has_class_flag c CInterface) then jm#invokeinterface else jm#invokevirtual) c.cl_path cf.cf_name (method_sig tl tr);
+			tr
 		| TField(_,FEnum(en,ef)) ->
 			let tl,_ = self#call_arguments ef.ef_type el in
 			let tr = self#vtype tr in

+ 18 - 1
src/optimization/inline.ml

@@ -619,7 +619,24 @@ class inline_state ctx ethis params cf f p = object(self)
 				if List.memq e params then (fun t -> t)
 				else map_type
 			in
-			Type.map_expr_type (map_expr_type map_type) map_type (map_var map_type) e
+			let e = Type.map_expr_type (map_expr_type map_type) map_type (map_var map_type) e in
+			match e.eexpr with
+			| TCall({eexpr = TField(e1,fa)} as ef,el) ->
+				let recall fh cf =
+					let fa = FieldAccess.create e1 cf fh false ef.epos in
+					let fcc = CallUnification.unify_field_call ctx fa el [] e.epos false in
+					fcc.fc_data()
+				in
+				begin match fa with
+				| FStatic(c,cf) when has_class_field_flag cf CfOverload ->
+					recall (FHStatic c) cf
+				| FInstance(c,tl,cf) when has_class_field_flag cf CfOverload ->
+					recall (FHInstance(c,tl)) cf
+				| _ ->
+					e
+				end
+			| _ ->
+				e
 		in
 		let e = map_expr_type map_type e in
 		let rec drop_unused_vars e =

+ 3 - 0
src/typing/callUnification.ml

@@ -195,6 +195,9 @@ let unify_field_call ctx fa el_typed el p inline =
 						raise(Error(call_error,p))
 					end;
 					loop ((e,opt) :: acc_el) (arg :: acc_args) (fun t -> t) args el_typed
+				| [],_ :: _ ->
+					let call_error = Call_error(Too_many_arguments) in
+					raise(Error(call_error,p))
 				| _ ->
 					List.rev acc_el,List.rev acc_args,args
 			in