浏览代码

[java/cs] Set constants initialized on classes that derive from @:nativeGen . Closes #4000

Cauê Waneck 10 年之前
父节点
当前提交
abe32cafd1
共有 2 个文件被更改,包括 55 次插入1 次删除
  1. 1 1
      gencommon.ml
  2. 54 0
      tests/unit/src/unit/issues/Issue4000.hx

+ 1 - 1
gencommon.ml

@@ -2251,7 +2251,7 @@ struct
 										let rec add_fn e = match e.eexpr with
 											| TBlock(hd :: tl) -> (match hd.eexpr with
 												| TCall({ eexpr = TConst TSuper }, _) ->
-													if is_hxgen (TClassDecl cl) then
+													if not (OverloadingConstructor.descends_from_native_or_skipctor cl) then
 														{ e with eexpr = TBlock(vars @ (hd :: (funs @ tl))) }
 													else
 														{ e with eexpr = TBlock(hd :: (vars @ funs @ tl)) }

+ 54 - 0
tests/unit/src/unit/issues/Issue4000.hx

@@ -0,0 +1,54 @@
+package unit.issues;
+
+class Issue4000 extends Test
+{
+	public function test()
+	{
+		var c = new Child();
+		eq(c.i,1000);
+		eq(c.f,1.0);
+		eq(c.dyn.a,1);
+		eq(c.dyn.b,10);
+		f(c.b);
+#if (java || cs)
+		var c = new Child(42);
+		eq(c.i,42);
+		eq(c.f,1.0);
+		eq(c.dyn.a,1);
+		eq(c.dyn.b,10);
+		t(c.b);
+#end
+	}
+}
+
+@:nativeGen private class NativeGen
+{
+	public function new()
+	{
+	}
+}
+
+private class Child extends NativeGen
+{
+	public var i = 1000;
+	public var f = 1.0;
+	public var dyn = { a:1, b:10 };
+	public var b = true;
+
+#if (java || cs)
+	@:overload
+#end
+	public function new()
+	{
+		super();
+		this.b = false;
+	}
+
+#if (java || cs)
+	@:overload public function new(i:Float)
+	{
+		super();
+		this.i = Std.int(i);
+	}
+#end
+}