Browse Source

Merge branch 'development' of github.com:HaxeFoundation/haxe into strict-name-encoding

杨博 11 years ago
parent
commit
8d37c06520
4 changed files with 125 additions and 3 deletions
  1. 8 3
      gencommon.ml
  2. 36 0
      tests/unit/issues/Issue3138.hx
  3. 34 0
      tests/unit/issues/Issue3159.hx
  4. 47 0
      tests/unit/issues/Issue3171.hx

+ 8 - 3
gencommon.ml

@@ -10056,7 +10056,7 @@ struct
 												| Some o -> o
 											in
 											let e = { e with eexpr = TLocal v2; etype = basic.tnull e.etype } in
-											let const = mk_cast e.etype { e with eexpr = TConst(o); etype = v.v_type } in
+											let const = mk_cast e.etype { e with eexpr = TConst(o); etype = follow v.v_type } in
 											found := true;
 											{ e with eexpr = TIf({
 												eexpr = TBinop(Ast.OpEq, e, null e.etype e.epos);
@@ -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
 
@@ -10593,11 +10597,12 @@ struct
 								let old_args, old_ret = get_fun f.cf_type in
 								let args, ret = get_fun t in
 								let tf_args = List.map (fun (n,o,t) -> alloc_var n t, None) args in
+								let f3_mk_return = if is_void ret then (fun e -> e) else (fun e -> mk_return (mk_cast ret e)) in
 								f3.cf_expr <- Some {
 									eexpr = TFunction({
 										tf_args = tf_args;
 										tf_type = ret;
-										tf_expr = mk_block (mk_return (mk_cast ret {
+										tf_expr = mk_block (f3_mk_return {
 											eexpr = TCall(
 												{
 													eexpr = TField(
@@ -10609,7 +10614,7 @@ struct
 												List.map2 (fun (v,_) (_,_,t) -> mk_cast t (mk_local v p)) tf_args old_args);
 											etype = old_ret;
 											epos = p
-										}))
+										})
 									});
 									etype = t;
 									epos = p;

+ 36 - 0
tests/unit/issues/Issue3138.hx

@@ -0,0 +1,36 @@
+package unit.issues;
+
+class Issue3138 extends Test
+{
+	public function test()
+	{
+		var a = new B();
+#if (java || cs)
+		var b = new D();
+#end
+	}
+}
+
+private class A {
+    public function new(a) {}
+}
+
+private class B extends A {
+    public function new(?a = 1) {
+        super(a); // error CS0030: Cannot convert type 'int' to 'haxe.lang.Null<int>'
+    }
+}
+
+#if (cs || java)
+
+private class C {
+    public function new(a) {}
+}
+
+private class D extends C {
+    public function new(?a:Single = 1) {
+        super(a); // error CS0030: Cannot convert type 'int' to 'haxe.lang.Null<int>'
+    }
+}
+
+#end

+ 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;
+	}
+}

+ 47 - 0
tests/unit/issues/Issue3171.hx

@@ -0,0 +1,47 @@
+package unit.issues;
+
+class Issue3171 extends Test
+{
+#if (java || cs)
+	public function test()
+	{
+		var oint = new O2();
+		oint.foo(10);
+		eq(10,oint.lastVal);
+		f(oint.called);
+
+		var oint2:O<Int> = new O();
+		oint2.foo(10);
+		eq(0,oint2.lastVal);
+		t(oint2.called);
+
+		oint2 = new O2();
+		oint2.foo(20);
+		eq(20, oint2.lastVal);
+		f(oint2.called);
+	}
+#end
+}
+#if (java || cs)
+class O<T>
+{
+	public var lastVal = 0;
+	public var called = false;
+	public function new()
+	{
+	}
+
+	@:overload public function foo(t:T):Void
+	{
+		called = true;
+	}
+}
+
+class O2 extends O<Int>
+{
+	@:overload override public function foo(t:Int):Void
+	{
+		lastVal = t;
+	}
+}
+#end