浏览代码

Forward @:nativeTypeConstraints in closures to class filter (#7863)

* Forward @:nativeTypeConstraints in closures to class filter

* Remove :nativeTypeConstraints custom meta

* Add test for #7875

* Add another test for #4002

Note: this test was already passing with `@:nativeTypeConstraints`
on class Test, but this custom meta is being removed.
Rudy Ges 6 年之前
父节点
当前提交
ade3bf66e0

+ 7 - 2
src/codegen/gencommon/closuresToClass.ml

@@ -278,8 +278,9 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu
 
 let rec get_type_params acc t =
 	match t with
-		| TInst(( { cl_kind = KTypeParameter _ } as cl), []) ->
-			if List.memq cl acc then acc else cl :: acc
+		| TInst(( { cl_kind = KTypeParameter constraints } as cl), []) ->
+			let params = List.fold_left get_type_params acc constraints in
+			List.filter (fun t -> not (List.memq t acc)) (cl :: params) @ acc;
 		| TFun (params,tret) ->
 			List.fold_left get_type_params acc ( tret :: List.map (fun (_,_,t) -> t) params )
 		| TDynamic t ->
@@ -413,6 +414,10 @@ let configure gen ft =
 		let cls = mk_class (get gen.gcurrent_class).cl_module path tfunc.tf_expr.epos in
 		if in_unsafe then cls.cl_meta <- (Meta.Unsafe,[],null_pos) :: cls.cl_meta;
 
+		(* forward NativeGen meta for Cs target *)
+		if (Common.platform gen.gcon Cs) && not(is_hxgen (TClassDecl (get gen.gcurrent_class))) && Meta.has(Meta.NativeGen) (get gen.gcurrent_class).cl_meta then
+			cls.cl_meta <- (Meta.NativeGen,[],null_pos) :: cls.cl_meta;
+
 		if Common.defined gen.gcon Define.EraseGenerics then begin
 			cls.cl_meta <- (Meta.HaxeGeneric,[],null_pos) :: cls.cl_meta
 		end;

+ 1 - 1
src/core/meta.ml

@@ -450,4 +450,4 @@ let get_all () =
 		if d <> Last then d :: loop (i + 1)
 		else []
 	in
-	loop 0
+	loop 0

+ 1 - 4
src/generators/gencs.ml

@@ -1833,10 +1833,7 @@ let generate con =
 					let get_param_name t = match follow t with TInst(cl, _) -> snd cl.cl_path | _ -> assert false in
 					let params = sprintf "<%s>" (String.concat ", " (List.map (fun (_, tcl) -> get_param_name tcl) cl_params)) in
 					let params_extends =
-						if hxgen
-						(* this is temprorary, see https://github.com/HaxeFoundation/haxe/issues/3526 *)
-						|| not (Meta.has (Meta.Custom ":nativeTypeConstraints") cl.cl_meta)
-						then
+						if hxgen || not (Meta.has (Meta.NativeGen) cl.cl_meta) then
 							[""]
 						else
 							List.fold_left (fun acc (name, t) ->

+ 19 - 0
tests/misc/projects/Issue4002/Main.hx

@@ -0,0 +1,19 @@
+import cs.system.WeakReference_1;
+
+class Main {
+	public static function main() {
+		new Test<A>(new A());
+	}
+}
+
+@:nativeGen
+class Test<T:A> {
+	public function new(a:T) {
+		var ref:WeakReference_1<T> = new WeakReference_1(a);
+	}
+}
+
+class A {
+	public function new() {}
+}
+

+ 3 - 0
tests/misc/projects/Issue4002/compile.hxml

@@ -0,0 +1,3 @@
+--main Main
+-cs bin
+-D net-ver=45

+ 23 - 0
tests/misc/projects/Issue7875/Main.hx

@@ -0,0 +1,23 @@
+import cs.system.WeakReference_1;
+
+class Main {
+	public static function main() {
+		new Test<A>(new A());
+	}
+}
+
+@:nativeGen
+class Test<T:A> {
+	public function new(a:T) {
+		test(function() return new WeakReference_1(a));
+	}
+
+	function test(cb:Void->WeakReference_1<T>):Void {}
+
+
+}
+
+class A {
+	public function new() {}
+}
+

+ 3 - 0
tests/misc/projects/Issue7875/compile.hxml

@@ -0,0 +1,3 @@
+--main Main
+-cs bin
+-D net-ver=45