瀏覽代碼

[jvm] resolve overloads on static calls too

closes #9034
Aleksandr Kuzmenko 5 年之前
父節點
當前提交
8d88d86e6f
共有 3 個文件被更改,包括 36 次插入10 次删除
  1. 1 0
      extra/CHANGES.txt
  2. 21 10
      src/generators/genjvm.ml
  3. 14 0
      tests/unit/src/unit/issues/Issue9034.hx

+ 1 - 0
extra/CHANGES.txt

@@ -3,6 +3,7 @@
 	Bugfixes:
 
 	java : fix boolean arguments for `Type.createInstance(cls, args)` (#9025)
+	jvm : fix static overloads (#9034)
 	js : fix multiple appearances of the first object added to `ObjectMap` is passed to `ObjectMap.set(obj, v)` multiple times (#9026)
 	js : automatically wrap compound expressions with parentheses when passed to `js.Syntax.code()` (#9024)
 	windows : fix adding neko to PATH env var running windows installer (#9021)

+ 21 - 10
src/generators/genjvm.ml

@@ -82,6 +82,18 @@ let find_overload map_type c cf el =
 	in
 	loop (cf :: cf.cf_overloads)
 
+let filter_overloads candidates =
+	match Overloads.Resolution.reduce_compatible candidates with
+	| [_,_,(c,cf)] -> Some(c,cf)
+	| [] -> None
+	| ((_,_,(c,cf)) :: _) (* as resolved *) ->
+		(* let st = s_type (print_context()) in
+		print_endline (Printf.sprintf "Ambiguous overload for %s(%s)" name (String.concat ", " (List.map (fun e -> st e.etype) el)));
+		List.iter (fun (_,t,(c,cf)) ->
+			print_endline (Printf.sprintf "\tCandidate: %s.%s(%s)" (s_type_path c.cl_path) cf.cf_name (st t));
+		) resolved; *)
+		Some(c,cf)
+
 let find_overload_rec' is_ctor map_type c name el =
 	let candidates = ref [] in
 	let has_function t1 (_,t2,_) =
@@ -114,16 +126,7 @@ let find_overload_rec' is_ctor map_type c name el =
 		end;
 	in
 	loop map_type c;
-	match Overloads.Resolution.reduce_compatible (List.rev !candidates) with
-	| [_,_,(c,cf)] -> Some(c,cf)
-	| [] -> None
-	| ((_,_,(c,cf)) :: _) (* as resolved *) ->
-		(* let st = s_type (print_context()) in
-		print_endline (Printf.sprintf "Ambiguous overload for %s(%s)" name (String.concat ", " (List.map (fun e -> st e.etype) el)));
-		List.iter (fun (_,t,(c,cf)) ->
-			print_endline (Printf.sprintf "\tCandidate: %s.%s(%s)" (s_type_path c.cl_path) cf.cf_name (st t));
-		) resolved; *)
-		Some(c,cf)
+	filter_overloads (List.rev !candidates)
 
 let find_overload_rec is_ctor map_type c cf el =
 	if Meta.has Meta.Overload cf.cf_meta || cf.cf_overloads <> [] then
@@ -1507,6 +1510,14 @@ 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 filter_overloads (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

+ 14 - 0
tests/unit/src/unit/issues/Issue9034.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+import unit.Test;
+
+class Issue9034 extends Test{
+	#if java
+	function test() {
+		bar(java.nio.file.Paths.get('build.hxml', new java.NativeArray(0)));
+		utest.Assert.pass();
+	}
+	#end
+
+	static public inline function bar(path:java.nio.file.Path):Void { }
+}