Переглянути джерело

[typer] also add CfGeneric

Simon Krajewski 5 роки тому
батько
коміт
04f6612e1d

+ 1 - 1
src/context/typecore.ml

@@ -402,7 +402,7 @@ let push_this ctx e = match e.eexpr with
 
 let is_removable_field ctx f =
 	not (has_class_field_flag f CfOverride) && (
-		has_class_field_flag f CfExtern || Meta.has Meta.Generic f.cf_meta
+		has_class_field_flag f CfExtern || has_class_field_flag f CfGeneric
 		|| (match f.cf_kind with
 			| Var {v_read = AccRequire (s,_)} -> true
 			| Method MethMacro -> not ctx.in_macro

+ 1 - 0
src/core/tType.ml

@@ -393,6 +393,7 @@ type flag_tclass_field =
 	| CfAbstract
 	| CfOverload
 	| CfImpl
+	| CfGeneric
 
 type flag_tvar =
 	| VCaptured

+ 1 - 1
src/macro/eval/evalPrototype.ml

@@ -170,7 +170,7 @@ module PrototypeBuilder = struct
 end
 
 let is_removable_field cf =
-	has_class_field_flag cf CfExtern || Meta.has Meta.Generic cf.cf_meta
+	has_class_field_flag cf CfExtern || has_class_field_flag cf CfGeneric
 
 let is_persistent cf =
 	Meta.has Meta.Persistent cf.cf_meta

+ 2 - 6
src/typing/calls.ml

@@ -433,11 +433,7 @@ let type_generic_function ctx fa el_typed el with_type p =
 				);
 				cf2.cf_kind <- cf.cf_kind;
 				if not (has_class_field_flag cf CfPublic) then remove_class_field_flag cf2 CfPublic;
-				let metadata = List.filter (fun (m,_,_) -> match m with
-					| Meta.Generic -> false
-					| _ -> true
-				) cf.cf_meta in
-				cf2.cf_meta <- (Meta.NoCompletion,[],p) :: (Meta.NoUsing,[],p) :: (Meta.GenericInstance,[],p) :: metadata
+				cf2.cf_meta <- (Meta.NoCompletion,[],p) :: (Meta.NoUsing,[],p) :: (Meta.GenericInstance,[],p) :: cf.cf_meta
 			in
 			let mk_cf2 name =
 				mk_field ~static:stat name (map_monos cf.cf_type) cf.cf_pos cf.cf_name_pos
@@ -614,7 +610,7 @@ object(self)
 		match fa.fa_field.cf_kind with
 		| Method (MethNormal | MethInline | MethDynamic) ->
 			check_assign();
-			 if Meta.has Meta.Generic fa.fa_field.cf_meta then begin
+			 if has_class_field_flag fa.fa_field CfGeneric then begin
 				type_generic_function ctx fa el_typed el with_type p
 			end else
 				self#make_field_call fa el_typed el

+ 1 - 1
src/typing/fields.ml

@@ -143,7 +143,7 @@ let field_access ctx mode f famode e p =
 			| MethMacro, MGet ->
 				display_error ctx "Macro functions must be called immediately" p; normal()
 			| _ , MGet ->
-				if Meta.has Meta.Generic f.cf_meta then display_error ctx "Cannot create closure on generic function" p;
+				if has_class_field_flag f CfGeneric then display_error ctx "Cannot create closure on generic function" p;
 				normal()
 			| _ ->
 				normal()

+ 1 - 1
src/typing/typeloadCheck.ml

@@ -39,7 +39,7 @@ let is_generic_parameter ctx c =
 	(* first check field parameters, then class parameters *)
 	try
 		ignore (List.assoc (snd c.cl_path) ctx.curfield.cf_params);
-		Meta.has Meta.Generic ctx.curfield.cf_meta
+		has_class_field_flag ctx.curfield CfGeneric
 	with Not_found -> try
 		ignore(List.assoc (snd c.cl_path) ctx.type_params);
 		(match ctx.curclass.cl_kind with | KGeneric -> true | _ -> false);

+ 4 - 1
src/typing/typeloadFields.ml

@@ -73,6 +73,7 @@ type field_init_ctx = {
 	is_abstract_member : bool;
 	is_display_field : bool;
 	is_field_debug : bool;
+	is_generic : bool;
 	field_kind : field_kind;
 	display_modifier : placed_access option;
 	mutable do_bind : bool;
@@ -611,6 +612,7 @@ let create_field_context (ctx,cctx) c cff =
 		is_field_debug = cctx.is_class_debug || Meta.has (Meta.Custom ":debug.typeload") cff.cff_meta;
 		display_modifier = display_modifier;
 		is_abstract_member = is_abstract_member;
+		is_generic = Meta.has Meta.Generic cff.cff_meta;
 		field_kind = field_kind;
 		do_bind = (((not ((has_class_flag c CExtern) || !is_extern) || is_inline) && not is_abstract && not (has_class_flag c CInterface)) || field_kind = FKInit);
 		do_add = true;
@@ -1051,7 +1053,7 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
 
 let create_method (ctx,cctx,fctx) c f fd p =
 	let params = TypeloadFunction.type_function_params ctx fd (fst f.cff_name) p in
-	if Meta.has Meta.Generic f.cff_meta then begin
+	if fctx.is_generic then begin
 		if params = [] then error (fst f.cff_name ^ ": Generic functions must have type parameters") p;
 	end;
 	let fd = if fctx.is_macro && not ctx.in_macro && not fctx.is_static then
@@ -1159,6 +1161,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
 	if fctx.is_abstract then add_class_field_flag cf CfAbstract;
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
+	if fctx.is_generic then add_class_field_flag cf CfGeneric;
 	begin match fctx.overload with
 	| Some p ->
 		if ctx.com.config.pf_overload then