Преглед изворни кода

[java/cs] Correctly restrict adding the abstract's own type params

To only the non-static functions

Closes #4460
Closes #4459
Cauê Waneck пре 10 година
родитељ
комит
9990279864
2 измењених фајлова са 33 додато и 3 уклоњено
  1. 5 3
      gencommon.ml
  2. 28 0
      tests/unit/src/unit/issues/Issue4460.hx

+ 5 - 3
gencommon.ml

@@ -10979,11 +10979,13 @@ struct
 			match md with
 				| TClassDecl ({ cl_kind = KAbstractImpl a } as c) ->
 						List.iter (function
-							| ({ cf_type = TFun( ("this",_,_) :: _, _ ) } as cf) when Meta.has Meta.Impl cf.cf_meta ->
-								(* add type parameters to all implementation functions *)
-								cf.cf_params <- cf.cf_params @ a.a_params
 							| ({ cf_name = "_new" } as cf) ->
 								cf.cf_params <- cf.cf_params @ a.a_params
+							| cf when Meta.has Meta.Impl cf.cf_meta ->
+								(match cf.cf_expr with
+									| Some({ eexpr = TFunction({ tf_args = (v, _) :: _ }) }) when Meta.has Meta.This v.v_meta ->
+										cf.cf_params <- cf.cf_params @ a.a_params
+									| _ -> ())
 							| _ -> ()
 						) c.cl_ordered_statics;
 						Some md

+ 28 - 0
tests/unit/src/unit/issues/Issue4460.hx

@@ -0,0 +1,28 @@
+package unit.issues;
+
+class Issue4460 extends Test
+{
+	public function test()
+	{
+		var arr = new LikeArray([1,2,3,4]);
+		arr = arr.slice(1);
+		var arr2 = arr.arr();
+		eq(arr2[0], 2);
+	}
+}
+
+private abstract LikeArray<T>(Array<T>)
+{
+	inline public function new(arr)
+	{
+		this = arr;
+	}
+
+	public function slice(pos:Int, ?end:Int):LikeArray<T>
+		return new LikeArray(this.slice(pos,end));
+
+	public function arr()
+	{
+		return this;
+	}
+}