Просмотр исходного кода

[cs] Correctly set hxgen of an abstract / abstract implementation to the underlying type. Closes #3248

Cauê Waneck 11 лет назад
Родитель
Сommit
00eeff6071
2 измененных файлов с 43 добавлено и 2 удалено
  1. 9 2
      gencommon.ml
  2. 34 0
      tests/unit/issues/Issue3248.hx

+ 9 - 2
gencommon.ml

@@ -1504,8 +1504,10 @@ struct
 		basically, everything that is extern is assumed to not be hxgen, unless meta :hxgen is set, and
 		everything that is not extern is assumed to be hxgen, unless meta :nativegen is set
 	*)
-	let default_hxgen_func md =
+	let rec default_hxgen_func md =
 		match md with
+			| TClassDecl { cl_kind = KAbstractImpl a } ->
+				default_hxgen_func (TAbstractDecl a)
 			| TClassDecl cl ->
 				let rec is_hxgen_class (c,_) =
 					if c.cl_extern then begin
@@ -1530,7 +1532,12 @@ struct
 
 				is_hxgen_class (cl,[])
 			| TEnumDecl e -> if e.e_extern then Meta.has Meta.HxGen e.e_meta else not (Meta.has Meta.NativeGen e.e_meta)
-			| TAbstractDecl a -> not (Meta.has Meta.NativeGen a.a_meta)
+			| TAbstractDecl a when Meta.has Meta.CoreType a.a_meta -> not (Meta.has Meta.NativeGen a.a_meta)
+			| TAbstractDecl a -> (match follow a.a_this with
+				| TInst _ | TEnum _ | TAbstract _ ->
+					default_hxgen_func (t_to_md (follow a.a_this))
+				| _ ->
+					Meta.has Meta.NativeGen a.a_meta)
 			| TTypeDecl t -> (* TODO see when would we use this *)
 				false
 

+ 34 - 0
tests/unit/issues/Issue3248.hx

@@ -0,0 +1,34 @@
+package unit.issues;
+import haxe.ds.Vector;
+
+class Issue3248 extends Test {
+	public function test()
+	{
+		var a:AbstractBar<Foo> = new Bar<Foo>(new Vector(4));
+		eq(4,a.bar());
+	}
+}
+
+private class Foo {}
+
+@:nativeGen private class Bar<T>
+{
+	public var arr:Vector<T>;
+	public function new(arr)
+	{
+		this.arr = arr;
+	}
+}
+
+abstract AbstractBar<T>(Bar<T>) from Bar<T>
+{
+	public function new(ethis)
+	{
+		this= ethis;
+	}
+
+	public function bar()
+	{
+		return this.arr.length;
+	}
+}