소스 검색

[java] fix default args for Reflect.callMethod()
fixes #8975

Aleksandr Kuzmenko 5 년 전
부모
커밋
99b5986a76
2개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 9 3
      src/codegen/gencommon/reflectionCFs.ml
  2. 11 0
      tests/unit/src/unit/issues/Issue8975.hx

+ 9 - 3
src/codegen/gencommon/reflectionCFs.ml

@@ -1169,6 +1169,7 @@ let implement_invokeField ctx slow_invoke cl =
 			has_method := true;
 			let i = ref 0 in
 			let dyn_arg_local = mk_local dynamic_arg pos in
+			let dyn_arg_length = field dyn_arg_local "length" ctx.rcf_gen.gcon.basic.tint pos in
 			let cases = List.map (switch_case ctx pos) names in
 
 			let mk_this_call cf params =
@@ -1177,10 +1178,15 @@ let implement_invokeField ctx slow_invoke cl =
 			in
 			(cases,
 				mk_return (
-					mk_this_call cf (List.map (fun (name,_,t) ->
-						let ret = { eexpr = TArray(dyn_arg_local, make_int ctx.rcf_gen.gcon.basic !i pos); etype = t_dynamic; epos = pos } in
+					mk_this_call cf (List.map (fun (name,optional,t) ->
+						let idx = make_int ctx.rcf_gen.gcon.basic !i pos in
+						let ret = { eexpr = TArray(dyn_arg_local, idx); etype = t_dynamic; epos = pos } in
 						incr i;
-						ret
+						if optional then
+							let condition = binop OpGt dyn_arg_length idx ctx.rcf_gen.gcon.basic.tbool pos in
+							mk (TIf (condition, ret, Some (make_null ret.etype pos))) ret.etype pos
+						else
+							ret
 					) (fst (get_fun (cf.cf_type))))
 				)
 			)

+ 11 - 0
tests/unit/src/unit/issues/Issue8975.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue8975 extends unit.Test {
+	function test() {
+		eq('Alpha10', Reflect.callMethod(this, doIt, ['Alpha']));
+	}
+
+	function doIt(prefix:String, suffix:Int = 10):String {
+		return prefix + suffix;
+	}
+}