Browse Source

properly build generics in TField now that we have the type parameters (closes #3109)

Simon Krajewski 10 years ago
parent
commit
a732afe831
2 changed files with 49 additions and 3 deletions
  1. 6 3
      codegen.ml
  2. 43 0
      tests/unit/src/unit/issues/Issue3109.hx

+ 6 - 3
codegen.ml

@@ -274,9 +274,12 @@ let generic_substitute_expr gctx e =
 	in
 	let rec build_expr e =
 		match e.eexpr with
-		| TField(e1, FInstance({cl_kind = KGeneric},_,cf)) ->
-			build_expr {e with eexpr = TField(e1,quick_field_dynamic (generic_substitute_type gctx (e1.etype)) cf.cf_name)}
-		| _ -> map_expr_type build_expr (generic_substitute_type gctx) build_var e
+		| TField(e1, FInstance({cl_kind = KGeneric} as c,tl,cf)) ->
+			let _, _, f = gctx.ctx.g.do_build_instance gctx.ctx (TClassDecl c) gctx.p in
+			let t = f (List.map (generic_substitute_type gctx) tl) in
+			build_expr {e with eexpr = TField(e1,quick_field t cf.cf_name)}
+		| _ ->
+			map_expr_type build_expr (generic_substitute_type gctx) build_var e
 	in
 	build_expr e
 

+ 43 - 0
tests/unit/src/unit/issues/Issue3109.hx

@@ -0,0 +1,43 @@
+package unit.issues;
+
+class TT{}
+
+@:generic
+private class C1<T> {
+	public var ot:Int;
+	public function new() {
+		ot = 12;
+	}
+}
+
+//@:generic
+private class SC1<T> extends C1<T>{
+	public function new(){
+		super();
+	}
+}
+
+@:generic
+private class C2<T>{
+	var t:T;
+	public function new(t) {
+		this.t = t;
+	}
+}
+
+@:generic
+private class SC2<T> extends C2<SC1<T>>{
+	public function f(){
+		return t.ot;
+	}
+	public function new(){
+		super(new SC1());
+	}
+}
+
+class Issue3109 extends Test {
+	function test() {
+		var v:SC2<TT> = new SC2<TT>();
+		eq(12, v.f());
+	}
+}