ソースを参照

Merge branch 'development' into hxb_server_cache_simn_cleanup

Simon Krajewski 1 年間 前
コミット
c4a27d2fe4

+ 2 - 7
src/codegen/codegen.ml

@@ -307,7 +307,7 @@ module Dump = struct
 				| Some f -> print_field false f);
 				List.iter (print_field false) c.cl_ordered_fields;
 				List.iter (print_field true) c.cl_ordered_statics;
-				(match c.cl_init with
+				(match TClass.get_cl_init c with
 				| None -> ()
 				| Some e ->
 					print "\n\tstatic function __init__() ";
@@ -490,14 +490,9 @@ let map_source_header com f =
 
 (* Static extensions for classes *)
 module ExtClass = struct
-
-	let add_cl_init c e = match c.cl_init with
-			| None -> c.cl_init <- Some e
-			| Some e' -> c.cl_init <- Some (concat e' e)
-
 	let add_static_init c cf e p =
 		let ethis = Texpr.Builder.make_static_this c p in
 		let ef1 = mk (TField(ethis,FStatic(c,cf))) cf.cf_type p in
 		let e_assign = mk (TBinop(OpAssign,ef1,e)) e.etype p in
-		add_cl_init c e_assign
+		TClass.add_cl_init c e_assign
 end

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

@@ -723,8 +723,8 @@ let run_filters_from gen t filters =
 		gen.gcurrent_classfield <- None;
 		(match c.cl_init with
 		| None -> ()
-		| Some e ->
-			c.cl_init <- Some (List.fold_left (fun e f -> f e) e filters));
+		| Some f ->
+			process_field f);
 	| TClassDecl _ | TEnumDecl _ | TTypeDecl _ | TAbstractDecl _ ->
 		()
 

+ 2 - 2
src/codegen/gencommon/initFunction.ml

@@ -71,7 +71,7 @@ let handle_override_dynfun acc e this field =
 
 let handle_class gen cl =
 	let com = gen.gcon in
-	let init = match cl.cl_init with
+	let init = match TClass.get_cl_init cl with
 		| None -> []
 		| Some i -> [i]
 	in
@@ -109,7 +109,7 @@ let handle_class gen cl =
 	let init = List.rev init in
 	(match init with
 	| [] -> cl.cl_init <- None
-	| _ -> cl.cl_init <- Some (mk (TBlock init) com.basic.tvoid cl.cl_pos));
+	| _ -> TClass.set_cl_init cl (mk (TBlock init) com.basic.tvoid cl.cl_pos));
 
 	(* FIXME: find a way to tell OverloadingConstructor to execute this code even with empty constructors *)
 	let vars, funs = List.fold_left (fun (acc_vars,acc_funs) cf ->

+ 1 - 1
src/context/display/deprecationCheck.ml

@@ -107,7 +107,7 @@ let run com =
 		| TClassDecl c when not (Meta.has Meta.Deprecated c.cl_meta) ->
 			let dctx = {dctx with class_meta = c.cl_meta; curmod = c.cl_module} in
 			(match c.cl_constructor with None -> () | Some cf -> run_on_field dctx cf);
-			(match c.cl_init with None -> () | Some e -> run_on_expr dctx e);
+			(match TClass.get_cl_init c with None -> () | Some e -> run_on_expr dctx e);
 			List.iter (run_on_field dctx) c.cl_ordered_statics;
 			List.iter (run_on_field dctx) c.cl_ordered_fields;
 		| _ ->

+ 1 - 1
src/core/json/genjson.ml

@@ -621,7 +621,7 @@ let generate_class ctx c =
 		"fields",jlist (generate_class_field ctx CFSMember) c.cl_ordered_fields;
 		"statics",jlist (generate_class_field ctx CFSStatic) c.cl_ordered_statics;
 		"constructor",jopt (generate_class_field ctx CFSConstructor) c.cl_constructor;
-		"init",jopt (generate_texpr ctx) c.cl_init;
+		"init",jopt (generate_texpr ctx) (TClass.get_cl_init c);
 		"overrides",jlist (classfield_ref ctx) (List.filter (fun cf -> has_class_field_flag cf CfOverride) c.cl_ordered_fields);
 		"isExtern",jbool (has_class_flag c CExtern);
 		"isFinal",jbool (has_class_flag c CFinal);

+ 2 - 0
src/core/tFunctions.ml

@@ -211,6 +211,8 @@ let find_field c name kind =
 		PMap.find name c.cl_statics
 	| CfrMember ->
 		PMap.find name c.cl_fields
+	| CfrInit ->
+		begin match c.cl_init with Some cf -> cf | None -> raise Not_found end
 
 let null_module = {
 	m_id = alloc_mid();

+ 24 - 0
src/core/tOther.ml

@@ -412,6 +412,30 @@ module TClass = struct
 		in
 		let apply = apply_params c.cl_params tl in
 		loop apply c
+
+
+	let get_cl_init c = match c.cl_init with
+		| Some {cf_expr = Some e} -> Some e
+		| _ -> None
+
+	let modify_cl_init c e append = match c.cl_init with
+		| Some cf ->
+			begin match cf.cf_expr with
+				| Some e' when append ->
+					cf.cf_expr <- Some (concat e' e)
+				| _ ->
+					cf.cf_expr <- Some e
+			end
+		| None ->
+			let cf = mk_field "__init__" t_dynamic null_pos null_pos in
+			cf.cf_expr <- Some e;
+			c.cl_init <- Some cf
+
+	let add_cl_init c e =
+		modify_cl_init c e true
+
+	let set_cl_init c e =
+		modify_cl_init c e false
 end
 
 let s_class_path c =

+ 2 - 1
src/core/tPrinting.ml

@@ -413,6 +413,7 @@ let s_class_field_ref_kind = function
 	| CfrStatic -> "CfrStatic"
 	| CfrMember -> "CfrMember"
 	| CfrConstructor -> "CfrConstructor"
+	| CfrInit -> "CfrInit"
 
 module Printer = struct
 
@@ -506,7 +507,7 @@ module Printer = struct
 			"cl_super",s_opt (fun (c,tl) -> s_type (TInst(c,tl))) c.cl_super;
 			"cl_implements",s_list ", " (fun (c,tl) -> s_type (TInst(c,tl))) c.cl_implements;
 			"cl_array_access",s_opt s_type c.cl_array_access;
-			"cl_init",s_opt (s_expr_ast true "" s_type) c.cl_init;
+			"cl_init",s_opt (s_expr_ast true "" s_type) (TOther.TClass.get_cl_init c);
 			"cl_constructor",s_opt (s_tclass_field (tabs ^ "\t")) c.cl_constructor;
 			"cl_ordered_fields",s_list "\n\t" (s_tclass_field (tabs ^ "\t")) c.cl_ordered_fields;
 			"cl_ordered_statics",s_list "\n\t" (s_tclass_field (tabs ^ "\t")) c.cl_ordered_statics;

+ 2 - 1
src/core/tType.ml

@@ -300,7 +300,7 @@ and tclass = {
 	mutable cl_dynamic : t option;
 	mutable cl_array_access : t option;
 	mutable cl_constructor : tclass_field option;
-	mutable cl_init : texpr option;
+	mutable cl_init : tclass_field option;
 
 	mutable cl_build : unit -> build_state;
 	(*
@@ -421,6 +421,7 @@ and class_field_ref_kind =
 	| CfrStatic
 	| CfrMember
 	| CfrConstructor
+	| CfrInit
 
 and class_field_ref = {
 	cfr_sign : string;

+ 2 - 3
src/filters/filters.ml

@@ -666,15 +666,14 @@ let save_class_state com t =
 		let csr = Option.map (mk_field_restore) c.cl_constructor in
 		let ofr = List.map (mk_field_restore) c.cl_ordered_fields in
 		let osr = List.map (mk_field_restore) c.cl_ordered_statics in
-		let init = c.cl_init in
-		Option.may save_vars init;
+		let init = Option.map mk_field_restore c.cl_init in
 		c.cl_restore <- (fun() ->
 			c.cl_super <- sup;
 			c.cl_implements <- impl;
 			c.cl_meta <- meta;
 			if ext then add_class_flag c CExtern else remove_class_flag c CExtern;
 			c.cl_path <- path;
-			c.cl_init <- init;
+			c.cl_init <- Option.map restore_field init;
 			c.cl_ordered_fields <- List.map restore_field ofr;
 			c.cl_ordered_statics <- List.map restore_field osr;
 			c.cl_fields <- mk_pmap c.cl_ordered_fields;

+ 2 - 2
src/filters/filtersCommon.ml

@@ -81,11 +81,11 @@ let run_expression_filters ?(ignore_processed_status=false) ctx detail_times fil
 		(match c.cl_constructor with
 		| None -> ()
 		| Some f -> process_field f);
-		(match c.cl_init with
+		(match TClass.get_cl_init c with
 		| None -> ()
 		| Some e ->
 			let identifier = Printf.sprintf "%s.__init__" (s_type_path c.cl_path) in
-			c.cl_init <- Some (run (Some identifier) e));
+			TClass.set_cl_init c (run (Some identifier) e))
 	| TEnumDecl _ -> ()
 	| TTypeDecl _ -> ()
 	| TAbstractDecl _ -> ()

+ 6 - 6
src/generators/gencpp.ml

@@ -5003,7 +5003,7 @@ let find_referenced_types_flags ctx obj field_name super_deps constructor_deps h
    (* Body of main function *)
    (match obj with
    | TClassDecl class_def -> visit_class class_def;
-      (match class_def.cl_init with Some expression -> visit_params expression | _ -> ())
+      (match TClass.get_cl_init class_def with Some expression -> visit_params expression | _ -> ())
    | TEnumDecl enum_def -> visit_enum enum_def
    | TTypeDecl _ | TAbstractDecl _ -> (* These are expanded *) ());
 
@@ -5455,7 +5455,7 @@ let rec find_next_super_iteration ctx class_def =
 ;;
 
 let has_init_field class_def =
-   match class_def.cl_init with
+   match TClass.get_cl_init class_def with
    | Some _ -> true
    | _ -> false;;
 
@@ -5533,7 +5533,7 @@ let has_compare_field class_def =
 
 
 let has_boot_field class_def =
-   match class_def.cl_init with
+   match TClass.get_cl_init class_def with
    | None -> List.exists has_field_init (List.filter should_implement_field class_def.cl_ordered_statics)
    | _ -> true
 ;;
@@ -6094,7 +6094,7 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
       end;
    end;
 
-   (match class_def.cl_init with
+   (match TClass.get_cl_init class_def with
    | Some expression ->
       let ctx = file_context baseCtx cpp_file debug false in
       output_cpp ("void " ^ class_name^ "::__init__()");
@@ -8379,7 +8379,7 @@ let generate_script_class common_ctx script class_def =
    script#write ((string_of_int ( (List.length ordered_fields) +
                                  (List.length ordered_statics) +
                                  (match class_def.cl_constructor with Some _ -> 1 | _ -> 0 ) +
-                                 (match class_def.cl_init with Some _ -> 1 | _ -> 0 ) ) )
+                                 (match TClass.get_cl_init class_def with Some _ -> 1 | _ -> 0 ) ) )
                                  ^ "\n");
 
    let generate_field isStatic field =
@@ -8412,7 +8412,7 @@ let generate_script_class common_ctx script class_def =
    (match class_def.cl_constructor with
       | Some field  -> generate_field true field
       | _ -> () );
-   (match class_def.cl_init with
+   (match TClass.get_cl_init class_def with
       | Some expression  -> script#voidFunc true false "__init__" expression
       | _ -> () );
 

+ 3 - 7
src/generators/gencs.ml

@@ -2702,7 +2702,7 @@ let generate con =
 				end_block w
 			) main_expr;
 
-			(match cl.cl_init with
+			(match TClass.get_cl_init cl with
 				| None -> ()
 				| Some init ->
 					let needs_block,write_expr =
@@ -2957,7 +2957,7 @@ let generate con =
 		let super_map (cl,tl) = (cl, List.map run_follow_gen tl) in
 		List.iter (function
 			| TClassDecl cl ->
-					let all_fields = (Option.map_default (fun cf -> [cf]) [] cl.cl_constructor) @ cl.cl_ordered_fields @ cl.cl_ordered_statics in
+					let all_fields = (Option.map_default (fun cf -> [cf]) [] cl.cl_constructor) @ cl.cl_ordered_fields @ cl.cl_ordered_statics @ (Option.map_default (fun cf -> [cf]) [] cl.cl_init) in
 					List.iter (fun cf ->
 						cf.cf_type <- run_follow_gen cf.cf_type;
 						cf.cf_expr <- Option.map type_map cf.cf_expr;
@@ -2971,7 +2971,6 @@ let generate con =
 					) all_fields;
 				cl.cl_dynamic <- Option.map run_follow_gen cl.cl_dynamic;
 				cl.cl_array_access <- Option.map run_follow_gen cl.cl_array_access;
-				cl.cl_init <- Option.map type_map cl.cl_init;
 				cl.cl_super <- Option.map super_map cl.cl_super;
 				cl.cl_implements <- List.map super_map cl.cl_implements
 			| _ -> ()
@@ -3483,10 +3482,7 @@ let generate con =
 							mk_nativearray_decl gen basic.tint (List.map (fun (i,s) -> { eexpr = TConst(TInt (i)); etype = basic.tint; epos = c.cl_pos }) all) c.cl_pos;
 							mk_nativearray_decl gen basic.tstring (List.map (fun (i,s) -> { eexpr = TConst(TString (s)); etype = basic.tstring; epos = c.cl_pos }) all) c.cl_pos;
 						]); etype = basic.tvoid; epos = c.cl_pos } in
-						match c.cl_init with
-							| None -> c.cl_init <- Some expr
-							| Some e ->
-								c.cl_init <- Some { eexpr = TBlock([expr;e]); etype = basic.tvoid; epos = e.epos }
+						TClass.add_cl_init c expr
 					end
 				with | Not_found -> ())
 				| _ -> ()) gen.gtypes;

+ 1 - 1
src/generators/genhl.ml

@@ -3696,7 +3696,7 @@ let generate_static_init ctx types main =
 	(* init class statics *)
 	let init_exprs = ref [] in
 	List.iter (fun t ->
-		(match t with TClassDecl { cl_init = Some e } -> init_exprs := e :: !init_exprs | _ -> ());
+		(match t with TClassDecl { cl_init = Some {cf_expr = Some e} } -> init_exprs := e :: !init_exprs | _ -> ());
 		match t with
 		| TClassDecl c when not (has_class_flag c CExtern) ->
 			List.iter (fun f ->

+ 2 - 3
src/generators/genjava.ml

@@ -2201,7 +2201,7 @@ let generate con =
 			newline w
 		| _ -> ());
 
-		(match cl.cl_init with
+		(match TClass.get_cl_init cl with
 			| None -> ()
 			| Some init ->
 				write w "static";
@@ -2298,14 +2298,13 @@ let generate con =
 	let super_map (cl,tl) = (cl, List.map run_follow_gen tl) in
 	List.iter (function
 		| TClassDecl cl ->
-				let all_fields = (Option.map_default (fun cf -> [cf]) [] cl.cl_constructor) @ cl.cl_ordered_fields @ cl.cl_ordered_statics in
+				let all_fields = (Option.map_default (fun cf -> [cf]) [] cl.cl_constructor) @ cl.cl_ordered_fields @ cl.cl_ordered_statics @ (Option.map_default (fun cf -> [cf]) [] cl.cl_init)in
 				List.iter (fun cf ->
 					cf.cf_type <- run_follow_gen cf.cf_type;
 					cf.cf_expr <- Option.map type_map cf.cf_expr
 				) all_fields;
 			 cl.cl_dynamic <- Option.map run_follow_gen cl.cl_dynamic;
 			 cl.cl_array_access <- Option.map run_follow_gen cl.cl_array_access;
-			 cl.cl_init <- Option.map type_map cl.cl_init;
 			 cl.cl_super <- Option.map super_map cl.cl_super;
 			 cl.cl_implements <- List.map super_map cl.cl_implements
 		| _ -> ()

+ 1 - 1
src/generators/genjs.ml

@@ -1623,7 +1623,7 @@ let need_to_generate_interface ctx cl_iface =
 
 let generate_type ctx = function
 	| TClassDecl c ->
-		(match c.cl_init with
+		(match TClass.get_cl_init c with
 		| None -> ()
 		| Some e ->
 			ctx.inits <- e :: ctx.inits);

+ 2 - 5
src/generators/genjvm.ml

@@ -2532,10 +2532,7 @@ class tclass_to_jvm gctx c = object(self)
 			let p = null_pos in
 			let efield = Texpr.Builder.make_static_field c cf p in
 			let eop = mk (TBinop(OpAssign,efield,e)) cf.cf_type p in
-			begin match c.cl_init with
-			| None -> c.cl_init <- Some eop
-			| Some e -> c.cl_init <- Some (concat e eop)
-			end
+			TClass.add_cl_init c eop
 		in
 		begin match cf.cf_expr with
 			| None ->
@@ -2618,7 +2615,7 @@ class tclass_to_jvm gctx c = object(self)
 			| Some cf,None -> field MConstructor cf
 			| None,_ -> ()
 		end;
-		begin match c.cl_init with
+		begin match TClass.get_cl_init c with
 			| None ->
 				()
 			| Some e ->

+ 1 - 1
src/generators/genlua.ml

@@ -1840,7 +1840,7 @@ let generate_require ctx path meta =
 
 let generate_type ctx = function
     | TClassDecl c ->
-        (match c.cl_init with
+        (match TClass.get_cl_init c with
          | None -> ()
          | Some e ->
              ctx.inits <- e :: ctx.inits);

+ 1 - 1
src/generators/genneko.ml

@@ -555,7 +555,7 @@ let gen_enum ctx e =
 let gen_type ctx t acc =
 	match t with
 	| TClassDecl c ->
-		(match c.cl_init with
+		(match TClass.get_cl_init c with
 		| None -> ()
 		| Some e -> ctx.inits <- (c,e) :: ctx.inits);
 		if (has_class_flag c CExtern) then

+ 4 - 4
src/generators/genphp7.ml

@@ -959,7 +959,7 @@ class class_wrapper (cls) =
 			if (has_class_flag cls CInterface) then
 				false
 			else
-				match cls.cl_init with
+				match TClass.get_cl_init cls with
 					| Some _ -> true
 					| None ->
 						List.exists
@@ -978,7 +978,7 @@ class class_wrapper (cls) =
 			Returns expression of a user-defined static __init__ method
 			@see http://old.haxe.org/doc/advanced/magic#initialization-magic
 		*)
-		method! get_magic_init = cls.cl_init
+		method! get_magic_init = TClass.get_cl_init cls
 		(**
 			Returns hx source file name where this type was declared
 		*)
@@ -994,7 +994,7 @@ class class_wrapper (cls) =
 			if not (has_class_flag cls CExtern) then
 				None
 			else
-				match cls.cl_init with
+				match TClass.get_cl_init cls with
 					| None -> None
 					| Some body ->
 						let path =
@@ -1009,8 +1009,8 @@ class class_wrapper (cls) =
 								cl_ordered_fields  = [];
 								cl_ordered_statics  = [];
 								cl_constructor = None;
-								cl_init = Some body
 						} in
+						TClass.set_cl_init additional_cls body;
 						remove_class_flag additional_cls CExtern;
 						Some (TClassDecl additional_cls)
 	end

+ 1 - 1
src/generators/genpy.ml

@@ -2001,7 +2001,7 @@ module Generator = struct
 		!has_static_methods || !has_empty_static_vars
 
 	let gen_class_init ctx c =
-		match c.cl_init with
+		match TClass.get_cl_init c with
 			| None ->
 				()
 			| Some e ->

+ 1 - 1
src/generators/genswf.ml

@@ -142,7 +142,7 @@ let build_dependencies t =
 			add_field f;
 			if c.cl_path <> (["flash"],"Boot") then add_path (["flash"],"Boot") DKExpr;
 		);
-		(match c.cl_init with
+		(match TClass.get_cl_init c with
 		| None -> ()
 		| Some e -> add_expr e);
 		(match c.cl_super with

+ 2 - 2
src/generators/genswf9.ml

@@ -1982,7 +1982,7 @@ let generate_extern_inits ctx =
 	List.iter (fun t ->
 		match t with
 		| TClassDecl c when (has_class_flag c CExtern) ->
-			(match c.cl_init with
+			(match TClass.get_cl_init c with
 			| None -> ()
 			| Some e -> gen_expr ctx false e);
 		| _ -> ()
@@ -2035,7 +2035,7 @@ let generate_class_init ctx c hc =
 	if not (has_class_flag c CInterface) then write ctx HPopScope;
 	write ctx (HInitProp (type_path ctx c.cl_path));
 	if ctx.swc && c.cl_path = ctx.boot then generate_extern_inits ctx;
-	(match c.cl_init with
+	(match TClass.get_cl_init c with
 	| None -> ()
 	| Some e ->
 		gen_expr ctx false e;

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

@@ -211,7 +211,7 @@ let create_static_prototype ctx mt =
 			|  _ ->
 				()
 		) fields;
-		begin match c.cl_init with
+		begin match TClass.get_cl_init c with
 			| None -> ()
 			| Some e -> DynArray.add delays (false,(fun _ -> ignore(eval_expr ctx (EKMethod(key,key___init__)) e)))
 		end;

+ 1 - 1
src/macro/macroApi.ml

@@ -1169,7 +1169,7 @@ and encode_tclass c =
 		"fields", encode_ref c.cl_ordered_fields (encode_and_map_array encode_cfield) (fun() -> "class fields");
 		"statics", encode_ref c.cl_ordered_statics (encode_and_map_array encode_cfield) (fun() -> "class fields");
 		"constructor", (match c.cl_constructor with None -> vnull | Some cf -> encode_cfref cf);
-		"init", (match c.cl_init with None -> vnull | Some e -> encode_texpr e);
+		"init", (match TClass.get_cl_init c with None -> vnull | Some e -> encode_texpr e);
 		"overrides", (encode_array (List.map encode_cfref (List.filter (fun cf -> has_class_field_flag cf CfOverride) c.cl_ordered_fields)))
 	]
 

+ 2 - 2
src/optimization/analyzer.ml

@@ -1126,7 +1126,7 @@ module Run = struct
 			| None -> ()
 			| Some f -> process_field false f;
 		end;
-		begin match c.cl_init with
+		begin match TClass.get_cl_init c with
 			| None ->
 				()
 			| Some e ->
@@ -1138,7 +1138,7 @@ module Run = struct
 					| TFunction tf -> tf.tf_expr
 					| _ -> die "" __LOC__
 				in
-				c.cl_init <- Some e
+				TClass.set_cl_init c e
 		end
 
 	let run_on_type com config t =

+ 9 - 7
src/optimization/dce.ml

@@ -186,6 +186,11 @@ and mark_field dce c cf kind =
 			| None -> ()
 		in
 		loop c
+	| CfrInit ->
+		begin match c.cl_init with
+			| Some cf -> add c cf
+			| None -> ()
+		end
 	| CfrStatic | CfrMember ->
 		let stat = kind = CfrStatic in
 		if not (PMap.mem cf.cf_name (if stat then c.cl_statics else c.cl_fields)) then begin
@@ -209,7 +214,7 @@ let rec update_marked_class_fields dce c =
 		if has_class_field_flag cf CfMaybeUsed then mark_field dce c cf CfrMember
 	) c.cl_ordered_fields;
 	(* we always have to keep super classes and implemented interfaces *)
-	(match c.cl_init with None -> () | Some init -> dce.follow_expr dce init);
+	(match TClass.get_cl_init c with None -> () | Some init -> dce.follow_expr dce init);
 	List.iter (fun (c,_) -> mark_class dce c) c.cl_implements;
 	(match c.cl_super with None -> () | Some (csup,pl) -> mark_class dce csup);
 	pop()
@@ -763,11 +768,8 @@ let collect_entry_points dce com =
 				| None -> ()
 			end;
 			begin match c.cl_init with
-				| Some e when keep_class || Meta.has Meta.KeepInit c.cl_meta ->
-					(* create a fake field to deal with our internal logic (issue #3286) *)
-					let cf = mk_field "__init__" e.etype e.epos null_pos in
-					cf.cf_expr <- Some e;
-					loop CfrStatic cf
+				| Some cf when keep_class || Meta.has Meta.KeepInit c.cl_meta ->
+					loop CfrInit cf
 				| _ ->
 					()
 			end;
@@ -874,7 +876,7 @@ let sweep dce com =
 			let has_non_extern_fields = List.exists inef c.cl_ordered_fields || List.exists inef c.cl_ordered_statics in
 			(* we keep a class if it was used or has a used field *)
 			if has_class_flag c CUsed || has_non_extern_fields then loop (mt :: acc) l else begin
-				(match c.cl_init with
+				(match TClass.get_cl_init c with
 				| Some f when Meta.has Meta.KeepInit c.cl_meta ->
 					(* it means that we only need the __init__ block *)
 					add_class_flag c CExtern;

+ 1 - 1
src/typing/finalization.ml

@@ -179,7 +179,7 @@ let sort_types com (modules : module_lut) =
 	and walk_class p c =
 		(match c.cl_super with None -> () | Some (c,_) -> loop_class p c);
 		List.iter (fun (c,_) -> loop_class p c) c.cl_implements;
-		(match c.cl_init with
+		(match TClass.get_cl_init c with
 		| None -> ()
 		| Some e -> walk_expr p e);
 		PMap.iter (fun _ f ->

+ 1 - 1
src/typing/generic.ml

@@ -364,7 +364,7 @@ let build_generic_class ctx c p tl =
 			cf_new.cf_type <- TLazy r;
 			cf_new
 		in
-		if c.cl_init <> None then raise_typing_error "This class can't be generic" p;
+		if TClass.get_cl_init c <> None then raise_typing_error "This class can't be generic" p;
 		List.iter (fun cf -> match cf.cf_kind with
 			| Method MethMacro when not ctx.com.is_macro_context -> ()
 			| _ -> raise_typing_error "A generic class can't have static fields" cf.cf_pos

+ 1 - 1
src/typing/nullSafety.ml

@@ -1513,7 +1513,7 @@ class class_checker cls immediate_execution report =
 						self#check_accessors is_static f
 			end in
 			if is_safe_class then
-				Option.may ((self#get_checker (safety_mode cls_meta))#check_root_expr) cls.cl_init;
+				Option.may ((self#get_checker (safety_mode cls_meta))#check_root_expr) (TClass.get_cl_init cls);
 			Option.may (check_field false) cls.cl_constructor;
 			List.iter (check_field false) cls.cl_ordered_fields;
 			List.iter (check_field true) cls.cl_ordered_statics;

+ 22 - 32
src/typing/typeloadFields.ml

@@ -44,11 +44,6 @@ type class_init_ctx = {
 	mutable uninitialized_final : tclass_field list;
 }
 
-type field_kind =
-	| FKNormal
-	| FKConstructor
-	| FKInit
-
 type field_init_ctx = {
 	is_inline : bool;
 	is_final : bool;
@@ -63,7 +58,7 @@ type field_init_ctx = {
 	is_display_field : bool;
 	is_field_debug : bool;
 	is_generic : bool;
-	field_kind : field_kind;
+	field_kind : class_field_ref_kind;
 	display_modifier : placed_access option;
 	mutable do_bind : bool;
 	(* If true, cf_expr = None makes a difference in the logic. We insert a dummy expression in
@@ -117,11 +112,6 @@ let dump_class_context cctx =
 		"force_constructor",string_of_bool cctx.force_constructor;
 	]
 
-let s_field_kind = function
-	| FKNormal -> "FKNormal"
-	| FKConstructor -> "FKConstructor"
-	| FKInit -> "FKInit"
-
 let dump_field_context fctx =
 	Printer.s_record_fields "" [
 		"is_inline",string_of_bool fctx.is_inline;
@@ -131,7 +121,7 @@ let dump_field_context fctx =
 		"is_abstract_member",string_of_bool fctx.is_abstract_member;
 		"is_display_field",string_of_bool fctx.is_display_field;
 		"is_field_debug",string_of_bool fctx.is_field_debug;
-		"field_kind",s_field_kind fctx.field_kind;
+		"field_kind",s_class_field_ref_kind fctx.field_kind;
 		"do_bind",string_of_bool fctx.do_bind;
 		"expr_presence_matters",string_of_bool fctx.expr_presence_matters;
 	]
@@ -602,9 +592,9 @@ let create_field_context ctx cctx cff is_display_file display_modifier =
 	let overload = try Some (List.assoc AOverload cff.cff_access) with Not_found -> None in
 	let is_macro = List.mem_assoc AMacro cff.cff_access in
 	let field_kind = match fst cff.cff_name with
-		| "new" -> FKConstructor
-		| "__init__" when is_static -> FKInit
-		| _ -> FKNormal
+		| "new" -> CfrConstructor
+		| "__init__" when is_static -> CfrInit
+		| _ -> if is_static then CfrStatic else CfrMember
 	in
 	let default = try
 		let (_,_,p) = Meta.get Meta.JavaDefault cff.cff_meta in
@@ -629,7 +619,7 @@ let create_field_context ctx cctx cff is_display_file 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_bind = (((not ((has_class_flag c CExtern) || !is_extern) || is_inline) && not is_abstract && not (has_class_flag c CInterface)) || field_kind = CfrInit);
 		expr_presence_matters = false;
 		had_error = false;
 	} in
@@ -746,7 +736,7 @@ let check_field_display ctx fctx c cf =
 			| _ ->
 				(if fctx.is_static then
 					CFSStatic
-				else if fctx.field_kind = FKConstructor then
+				else if fctx.field_kind = CfrConstructor then
 					CFSConstructor
 				else
 					CFSMember), cf;
@@ -940,7 +930,7 @@ module TypeBinding = struct
 				| Some _ ->
 					if fctx.is_abstract_member then FunMemberAbstract else FunStatic
 				| None ->
-					if fctx.field_kind = FKConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
+					if fctx.field_kind = CfrConstructor then FunConstructor else if fctx.is_static then FunStatic else FunMember
 			) in
 			begin match ctx.com.platform with
 				| Java when is_java_native_function ctx cf.cf_meta cf.cf_pos ->
@@ -951,7 +941,7 @@ module TypeBinding = struct
 				| _ ->
 					if Meta.has Meta.DisplayOverride cf.cf_meta then DisplayEmitter.check_field_modifiers ctx c cf fctx.override fctx.display_modifier;
 					let f_check = match fctx.field_kind with
-						| FKNormal when not fctx.is_static ->
+						| CfrMember ->
 							begin match TypeloadCheck.check_overriding ctx c cf with
 							| NothingToDo ->
 								(fun () -> ())
@@ -976,10 +966,10 @@ module TypeBinding = struct
 						tf_type = ret;
 						tf_expr = e;
 					} in
-					if fctx.field_kind = FKInit then
+					if fctx.field_kind = CfrInit then
 						(match e.eexpr with
 						| TBlock [] | TBlock [{ eexpr = TConst _ }] | TConst _ | TObjectDecl [] -> ()
-						| _ -> c.cl_init <- Some e);
+						| _ -> TClass.set_cl_init c e);
 					cf.cf_expr <- Some (mk (TFunction tf) t p);
 					cf.cf_type <- t;
 					check_field_display ctx fctx c cf;
@@ -1268,7 +1258,7 @@ let setup_args_ret ctx cctx fctx name fd p =
 		else
 			def()
 	in
-	let ret = if fctx.field_kind = FKConstructor then
+	let ret = if fctx.field_kind = CfrConstructor then
 		ctx.t.tvoid
 	else begin
 		let def () =
@@ -1339,12 +1329,12 @@ let create_method (ctx,cctx,fctx) c f fd p =
 			}
 	end in
 	begin match (has_class_flag c CInterface),fctx.field_kind with
-		| true,FKConstructor ->
+		| true,CfrConstructor ->
 			raise_typing_error "An interface cannot have a constructor" p;
 		| true,_ ->
 			if not fctx.is_static && fd.f_expr <> None then unexpected_expression ctx.com fctx ("An interface method cannot have a body") p;
 			if fctx.is_inline && (has_class_flag c CInterface) then invalid_modifier ctx.com fctx "inline" "method of interface" p;
-		| false,FKConstructor ->
+		| false,CfrConstructor ->
 			if fctx.is_static then invalid_modifier ctx.com fctx "static" "constructor" p;
 			begin match fd.f_type with
 				| None -> ()
@@ -1379,7 +1369,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	if fctx.is_final then add_class_field_flag cf CfFinal;
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
 	if fctx.is_abstract then begin
-		if fctx.field_kind = FKConstructor then begin
+		if fctx.field_kind = CfrConstructor then begin
 			let p =
 				try List.assoc AAbstract f.cff_access
 				with Not_found -> p
@@ -1406,7 +1396,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	| Some p ->
 		if ctx.com.config.pf_overload then
 			add_class_field_flag cf CfOverload
-		else if fctx.field_kind = FKConstructor then
+		else if fctx.field_kind = CfrConstructor then
 			invalid_modifier ctx.com fctx "overload" "constructor" p
 		else begin
 			add_class_field_flag cf CfOverload;
@@ -1791,22 +1781,22 @@ let init_class ctx c p herits fields =
 			let ctx = create_typer_context_for_field ctx cctx fctx f in
 			if fctx.is_field_debug then print_endline ("Created field context: " ^ dump_field_context fctx);
 			let cf = init_field (ctx,cctx,fctx) f in
-			if fctx.field_kind = FKInit then begin
+			if fctx.field_kind = CfrInit then begin
 				if !has_init then
 					display_error ctx.com ("Duplicate class field declaration : " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name) cf.cf_name_pos
 				else
 					has_init := true
 			end;
 			if fctx.is_field_debug then print_endline ("Created field: " ^ Printer.s_tclass_field "" cf);
-			if fctx.is_static && (has_class_flag c CInterface) && fctx.field_kind <> FKInit && not cctx.is_lib && not ((has_class_flag c CExtern)) then
+			if fctx.is_static && (has_class_flag c CInterface) && fctx.field_kind <> CfrInit && not cctx.is_lib && not ((has_class_flag c CExtern)) then
 				raise_typing_error "You can only declare static fields in extern interfaces" p;
 			let req = check_require f.cff_meta in
-			let req = (match req with None -> if fctx.is_static || fctx.field_kind = FKConstructor then cl_req else None | _ -> req) in
+			let req = (match req with None -> if fctx.is_static || fctx.field_kind = CfrConstructor then cl_req else None | _ -> req) in
 			(match req with
 			| None -> ()
 			| Some r -> cf.cf_kind <- Var { v_read = AccRequire (fst r, snd r); v_write = AccRequire (fst r, snd r) });
 			begin match fctx.field_kind with
-			| FKConstructor ->
+			| CfrConstructor ->
 				begin match c.cl_super with
 				| Some ({ cl_constructor = Some ctor_sup } as c, _) when not (has_class_flag c CExtern) && has_class_field_flag ctor_sup CfFinal ->
 					ctx.com.error "Cannot override final constructor" cf.cf_pos
@@ -1823,9 +1813,9 @@ let init_class ctx c p herits fields =
 				| Some ctor ->
 						display_error ctx.com "Duplicate constructor" p
 				end
-			| FKInit ->
+			| CfrInit ->
 				()
-			| FKNormal ->
+			| CfrStatic | CfrMember ->
 				let dup = if fctx.is_static then PMap.exists cf.cf_name c.cl_fields || has_field cf.cf_name c.cl_super else PMap.exists cf.cf_name c.cl_statics in
 				if not cctx.is_native && not (has_class_flag c CExtern) && dup then raise_typing_error ("Same field name can't be used for both static and instance : " ^ cf.cf_name) p;
 				if fctx.override <> None then