浏览代码

changed generic keep handling again: force removal of all generics which have type parameters constrained to new:function

Simon Krajewski 12 年之前
父节点
当前提交
bd4275ab75
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11 7
      codegen.ml

+ 11 - 7
codegen.ml

@@ -274,6 +274,14 @@ let is_generic_parameter ctx c =
 	with Not_found ->
 	with Not_found ->
 		false
 		false
 
 
+let has_ctor_constraint c = match c.cl_kind with
+	| KTypeParameter tl ->
+		List.exists (fun t -> match follow t with
+			| TAnon a when PMap.mem "new" a.a_fields -> true
+			| _ -> false
+		) tl;
+	| _ -> false
+
 let rec build_generic ctx c p tl =
 let rec build_generic ctx c p tl =
 	let pack = fst c.cl_path in
 	let pack = fst c.cl_path in
 	let recurse = ref false in
 	let recurse = ref false in
@@ -282,12 +290,8 @@ let rec build_generic ctx c p tl =
 		| TInst (c2,tl) ->
 		| TInst (c2,tl) ->
 			(match c2.cl_kind with
 			(match c2.cl_kind with
 			| KTypeParameter tl ->
 			| KTypeParameter tl ->
-				List.iter (fun t -> match follow t with
-					| TAnon a when PMap.mem "new" a.a_fields ->
-						error "Type parameters with a constructor cannot be used non-generically" p
-					| _ -> ()
-				) tl;
-				if not (is_generic_parameter ctx c2) && not (has_meta ":?keepGenericBase" c.cl_meta) then c.cl_meta <- (":?keepGenericBase",[],p) :: c.cl_meta;
+				if not (is_generic_parameter ctx c2) && has_ctor_constraint c2 then
+					error "Type parameters with a constructor cannot be used non-generically" p;
 				recurse := true
 				recurse := true
 			| _ -> ());
 			| _ -> ());
 			List.iter check_recursive tl;
 			List.iter check_recursive tl;
@@ -598,7 +602,7 @@ let check_private_path ctx t = match t with
 
 
 (* Removes generic base classes *)
 (* Removes generic base classes *)
 let remove_generic_base ctx t = match t with
 let remove_generic_base ctx t = match t with
-	| TClassDecl c when c.cl_kind = KGeneric && not (has_meta ":?keepGenericBase" c.cl_meta) ->
+	| TClassDecl c when c.cl_kind = KGeneric && has_ctor_constraint c ->
 		c.cl_extern <- true
 		c.cl_extern <- true
 	| _ ->
 	| _ ->
 		()
 		()