Browse Source

[java] Cast type parameter values to object on _set_f implementations. Closes #2835

Cauê Waneck 11 years ago
parent
commit
9b89fd95fe
2 changed files with 33 additions and 1 deletions
  1. 9 1
      gencommon.ml
  2. 24 0
      tests/unit/issues/Issue2835.hx

+ 9 - 1
gencommon.ml

@@ -7358,6 +7358,14 @@ struct
         let do_field cf cf_type is_static =
           let get_field ethis = { eexpr = TField (ethis, if is_static then FStatic (cl, cf) else FInstance(cl, cf)); etype = cf_type; epos = pos } in
           let this = if is_static then mk_classtype_access cl pos else { eexpr = TConst(TThis); etype = t; epos = pos } in
+          let value_local = if is_float then match follow cf_type with
+            | TInst({ cl_kind = KTypeParameter _ }, _) ->
+              mk_cast t_dynamic value_local
+            | _ ->
+              value_local
+            else
+              value_local
+          in
 
           let ret =
           {
@@ -7450,7 +7458,7 @@ struct
         let do_field cf cf_type static =
           let this = if static then mk_classtype_access cl pos else { eexpr = TConst(TThis); etype = t; epos = pos } in
           match is_float, follow cf_type with
-            | true, TInst( { cl_kind = KTypeParameter _ }, [] ) ->
+            | true, TInst( { cl_kind = KTypeParameter _ }, _ ) ->
               mk_return (mk_cast basic.tfloat (mk_cast t_dynamic (get_field cf cf_type this cl cf.cf_name)))
             | _ ->
               mk_return (maybe_cast (get_field cf cf_type this cl cf.cf_name ))

+ 24 - 0
tests/unit/issues/Issue2835.hx

@@ -0,0 +1,24 @@
+package unit.issues;
+
+class Issue2835 extends unit.Test
+{
+	private function test()
+	{
+		var t = new Test(42);
+		eq(42,t.get());
+	}
+}
+
+private class Test<T:(Float)>
+{
+	public var value:T;
+	public function new(value)
+	{
+		this.value = value;
+	}
+
+	public function get():T
+	{
+		return value;
+	}
+}