Browse Source

[cs] TTypeExpr on classes with type parameters should use the actual
type-param class, not the non-generic interface.
Closes #3113

Cauê Waneck 10 years ago
parent
commit
b2452db565
2 changed files with 33 additions and 4 deletions
  1. 4 4
      gencs.ml
  2. 29 0
      tests/unit/src/unit/issues/Issue3113.hx

+ 4 - 4
gencs.ml

@@ -1292,10 +1292,10 @@ let configure gen =
 					(match mt with
 						| TClassDecl { cl_path = (["haxe"], "Int64") } -> write w ("global::" ^ module_s mt)
 						| TClassDecl { cl_path = (["haxe"], "Int32") } -> write w ("global::" ^ module_s mt)
-						| TClassDecl cl -> write w (t_s (TInst(cl, List.map (fun _ -> t_dynamic) cl.cl_params)))
-						| TEnumDecl en -> write w (t_s (TEnum(en, List.map (fun _ -> t_dynamic) en.e_params)))
-						| TTypeDecl td -> write w (t_s (gen.gfollow#run_f (TType(td, List.map (fun _ -> t_dynamic) td.t_params))))
-						| TAbstractDecl a -> write w (t_s (TAbstract(a, List.map (fun _ -> t_dynamic) a.a_params)))
+						| TClassDecl cl -> write w (t_s (TInst(cl, List.map (fun _ -> t_empty) cl.cl_params)));
+						| TEnumDecl en -> write w (t_s (TEnum(en, List.map (fun _ -> t_empty) en.e_params)))
+						| TTypeDecl td -> write w (t_s (gen.gfollow#run_f (TType(td, List.map (fun _ -> t_empty) td.t_params))))
+						| TAbstractDecl a -> write w (t_s (TAbstract(a, List.map (fun _ -> t_empty) a.a_params)))
 					)
 				| TParenthesis e ->
 					write w "("; expr_s w e; write w ")"

+ 29 - 0
tests/unit/src/unit/issues/Issue3113.hx

@@ -0,0 +1,29 @@
+package unit.issues;
+
+class Issue3113 extends Test
+{
+	public function test()
+	{
+		var t:TD = cast A;
+		eq( t.func(1, 2), 1 ); // works
+
+		t = cast B;
+		eq( t.func(1, 2), 1 ); // runtime: Unhandled Exception:
+		                       // Haxe Exception: Method 'func' not found on type B
+		                       // [ERROR] FATAL UNHANDLED EXCEPTION: Haxe Exception: Method 'func' not found on type B
+		                       // -> because of B having type parameter
+	}
+}
+
+private typedef TD = { function func<T>(x:T, y:T):T; }
+private class Base<T> {}
+
+@:keep private class A
+{
+    public static function func<G>(x:G, y:G):G { return x; }
+}
+
+@:keep private class B<T> extends Base<T>
+{
+    public static function func<G>(x:G, y:G):G { return x; }
+}