瀏覽代碼

prefer own constructor over parent class one when building @:generic classes (closes #2653)

Simon Krajewski 11 年之前
父節點
當前提交
4f5e7b14c4
共有 2 個文件被更改,包括 33 次插入1 次删除
  1. 1 1
      codegen.ml
  2. 32 0
      tests/unit/issues/Issue2653.hx

+ 1 - 1
codegen.ml

@@ -402,9 +402,9 @@ let rec build_generic ctx c p tl =
 		cg.cl_kind <- KGenericInstance (c,tl);
 		cg.cl_interface <- c.cl_interface;
 		cg.cl_constructor <- (match cg.cl_constructor, c.cl_constructor, c.cl_super with
+			| _, Some c, _ -> Some (build_field c)
 			| Some ctor, _, _ -> Some ctor
 			| None, None, None -> None
-			| None, Some c, _ -> Some (build_field c)
 			| _ -> error "Please define a constructor for this class in order to use it as generic" c.cl_pos
 		);
 		cg.cl_implements <- List.map (fun (i,tl) ->

+ 32 - 0
tests/unit/issues/Issue2653.hx

@@ -0,0 +1,32 @@
+package unit.issues;
+import unit.Test;
+
+private class BasicAsset {
+	public var s:String;
+	function new (s:String) {
+		this.s = s;
+	}
+}
+
+@:generic
+private class BasicTexture<R> extends BasicAsset {
+	public var i:Int;
+	public function new(i:Int, s:String) {
+		super(s);
+		this.i = i;
+    }
+}
+
+private class CanvasTexture extends BasicTexture<Int> {
+    public function new(i:Int, s:String) {
+		super(i, s);
+    }
+}
+
+class Issue2653 extends Test {
+	function test() {
+		var ct = new CanvasTexture(12, "foo");
+		eq(ct.i, 12);
+		eq(ct.s, "foo");
+	}
+}