浏览代码

[java/cs] Make sure we don't reimplement a fx override function more than once

Closes #6520
Caue Waneck 7 年之前
父节点
当前提交
f89c10524b
共有 2 个文件被更改,包括 64 次插入0 次删除
  1. 4 0
      src/codegen/gencommon/fixOverrides.ml
  2. 60 0
      tests/unit/src/unit/issues/Issue6520.hx

+ 4 - 0
src/codegen/gencommon/fixOverrides.ml

@@ -126,6 +126,10 @@ let run ~explicit_fn_name ~get_vmtype gen =
 								in
 								in
 								let p = f2.cf_pos in
 								let p = f2.cf_pos in
 								let newf = mk_class_field name real_ftype true f.cf_pos (Method MethNormal) f.cf_params in
 								let newf = mk_class_field name real_ftype true f.cf_pos (Method MethNormal) f.cf_params in
+								(* make sure that there isn't already an overload with the same exact type *)
+								if List.exists (fun (t,f2) ->
+									type_iseq (get_real_fun gen t) real_ftype
+								) overloads then raise Not_found;
 								let vars = List.map (fun (n,_,t) -> alloc_var n t) a2 in
 								let vars = List.map (fun (n,_,t) -> alloc_var n t) a2 in
 
 
 								let args = List.map2 (fun v (_,_,t) -> mk_cast t (mk_local v f2.cf_pos)) vars a1 in
 								let args = List.map2 (fun v (_,_,t) -> mk_cast t (mk_local v f2.cf_pos)) vars a1 in

+ 60 - 0
tests/unit/src/unit/issues/Issue6520.hx

@@ -0,0 +1,60 @@
+package unit.issues;
+
+class Issue6520 extends Test
+{
+  function test()
+  {
+    eq(new C().foo(10), 10);
+    eq(new D().foo("test"), "test");
+    eq(new CC().foo(10), 10);
+    eq(new DD().foo("test"), "test");
+  }
+}
+
+@:keep private interface A<T> {
+	public function foo (a:T):T;
+}
+
+@:keep private interface B<T> extends A<T> {
+	public function bar (a:T):T;
+}
+
+@:keep private class C implements A<Int> implements B<Int> {
+  public function new()
+  {
+  }
+	public function bar (a:Int):Int { return a;};
+	public function foo (a:Int):Int { return a;};
+}
+
+@:keep private class D implements A<String> implements B<String> {
+  public function new()
+  {
+  }
+	public function bar (a:String):String { return a;};
+	public function foo (a:String):String { return a;};
+}
+
+@:keep private interface AA<T> {
+	public function foo (a:T):T;
+}
+
+@:keep private interface BB<T> extends AA<T> {
+	public function bar (a:T):T;
+}
+
+@:keep private class CC implements AA<Int> implements BB<Int> implements A<Int> implements B<Int> {
+  public function new()
+  {
+  }
+	public function bar (a:Int):Int { return a;};
+	public function foo (a:Int):Int { return a;};
+}
+
+@:keep private class DD implements AA<String> implements BB<String> implements A<String> implements B<String> {
+  public function new()
+  {
+  }
+	public function bar (a:String):String { return a;};
+	public function foo (a:String):String { return a;};
+}