浏览代码

[java/cs] Support dynamic functions in interfaces. Closes #3159

Cauê Waneck 11 年之前
父节点
当前提交
ac16080505
共有 2 个文件被更改,包括 38 次插入0 次删除
  1. 4 0
      gencommon.ml
  2. 34 0
      tests/unit/issues/Issue3159.hx

+ 4 - 0
gencommon.ml

@@ -10149,6 +10149,10 @@ struct
 							);
 							cl.cl_fields <- PMap.remove cf.cf_name cl.cl_fields;
 							false
+						| Method MethDynamic ->
+							(* TODO OPTIMIZATION - add a `_dispatch` method to the interface which will call the dynamic function itself *)
+							cl.cl_fields <- PMap.remove cf.cf_name cl.cl_fields;
+							false
 						| _ -> true
 				) cl.cl_ordered_fields in
 

+ 34 - 0
tests/unit/issues/Issue3159.hx

@@ -0,0 +1,34 @@
+package unit.issues;
+
+class Issue3159 extends Test
+{
+	public function test()
+	{
+		var dmet = new DynamicMethod();
+		f(dmet.hasCalled);
+		var test:IHasDynamicMethod = dmet;
+		test.foo();
+		t(dmet.hasCalled);
+		test.foo = function() dmet.hasCalled = false;
+		test.foo();
+		f(dmet.hasCalled);
+	}
+}
+
+interface IHasDynamicMethod
+{
+  dynamic function foo():Void;
+}
+
+private class DynamicMethod implements IHasDynamicMethod
+{
+	public var hasCalled = false;
+	public function new()
+	{
+	}
+
+	dynamic public function foo()
+	{
+		hasCalled = true;
+	}
+}