Pārlūkot izejas kodu

fix detection of `@:generic` classes with constructor constraints (closes #4070)

Simon Krajewski 10 gadi atpakaļ
vecāks
revīzija
523c860c69

+ 1 - 0
.gitignore

@@ -70,3 +70,4 @@ tests/misc/projects/*/*.n
 tests/unit/bin/
 tests/*.n
 tests/misc/projects/Issue3756/cpp/
+tests/misc/projects/Issue4070/cpp/

+ 1 - 0
extra/CHANGES.txt

@@ -2,6 +2,7 @@
 
 	Bugfixes:
 
+	all : fixed detection of @:generic classes with constructor constraints
 	js : added variable number of arguments support in js.html.* classes
 	js : fixed DCE issue related to printing enums
 

+ 9 - 1
filters.ml

@@ -761,7 +761,15 @@ let save_class_state ctx t = match t with
 
 (* PASS 2 begin *)
 
-let is_removable_class c = c.cl_kind = KGeneric && (Codegen.has_ctor_constraint c || Meta.has Meta.Remove c.cl_meta)
+let is_removable_class c =
+	c.cl_kind = KGeneric &&
+	(Meta.has Meta.Remove c.cl_meta ||
+	List.exists (fun (_,t) -> match follow t with
+		| TInst(c,_) ->
+			Codegen.has_ctor_constraint c
+		| _ ->
+			false
+	) c.cl_params)
 
 let remove_generic_base ctx t = match t with
 	| TClassDecl c when is_removable_class c ->

+ 18 - 0
tests/misc/projects/Issue4070/Main.hx

@@ -0,0 +1,18 @@
+class Test {
+    public function new() {}
+}
+
+class Main {
+    public static function main() {
+        new Generic<Test>();
+    }
+}
+
+@:generic
+class Generic<T:({function new():Void;})> {
+    var t:T;
+
+    public function new() {
+        t = new T();
+    }
+}

+ 2 - 0
tests/misc/projects/Issue4070/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+-cpp cpp