فهرست منبع

[cs] Temp fix for #3516 - use actual type for all cases but when we need to infer params

Cauê Waneck 11 سال پیش
والد
کامیت
ee1c365325
2فایلهای تغییر یافته به همراه34 افزوده شده و 1 حذف شده
  1. 6 1
      gencommon.ml
  2. 28 0
      tests/unit/src/unit/issues/Issue3516.hx

+ 6 - 1
gencommon.ml

@@ -6140,7 +6140,12 @@ struct
 				let cf, actual_t, error = match is_overload with
 					| false ->
 							(* since actual_t from FClassField already applies greal_type, we're using the get_overloads helper to get this info *)
-							cf,declared_t,false
+							let t = if cf.cf_params = [] then (* this if statement must be eliminated - it's a workaround for #3516 + infer params. *)
+								actual_t
+							else
+								declared_t
+							in
+							cf,t,false
 					| true ->
 					let (cf, actual_t, error), is_static = match f with
 						| FInstance(c,_,cf) | FClosure(Some c,cf) ->

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

@@ -0,0 +1,28 @@
+package unit.issues;
+
+class Issue3516 extends Test
+{
+	public function test()
+	{
+		var b = new B();
+		var c = b.uniqueFieldName(C);
+		t(Std.is(c, C));
+		t(c != null);
+	}
+}
+
+private class A<T> {
+    public function new() {}
+    public function uniqueFieldName(c:Class<T>):T {
+        return Type.createInstance(c, []);
+    }
+}
+
+private class B extends A<C> {}
+
+private class C {}
+
+class TestMain {
+    static function main() {
+    }
+}