Browse Source

[typer] handle e_type like a human being would

Simon Krajewski 1 year ago
parent
commit
f1b7c7c1bb

+ 4 - 4
src/core/tFunctions.ml

@@ -884,10 +884,10 @@ let class_module_type c =
 	let t = mk_anon ~fields:c.cl_statics (ref (ClassStatics c)) in
 	{ (mk_typedef c.cl_module path c.cl_pos null_pos t) with t_private = true}
 
-let enum_module_type m path p  =
-	let path = ([], "Enum<" ^ (s_type_path path) ^ ">") in
-	let t = mk_mono() in
-	{(mk_typedef m path p null_pos t) with t_private = true}
+let enum_module_type en fields =
+	let path = ([], "Enum<" ^ (s_type_path en.e_path) ^ ">") in
+	let t = mk_anon ~fields (ref (EnumStatics en)) in
+	{(mk_typedef en.e_module path en.e_pos null_pos t) with t_private = true}
 
 let abstract_module_type a tl =
 	let path = ([],Printf.sprintf "Abstract<%s>" (s_type_path a.a_path)) in

+ 1 - 1
src/core/tOther.ml

@@ -278,7 +278,7 @@ let mk_enum m path pos name_pos =
 		e_extern = false;
 		e_constrs = PMap.empty;
 		e_names = [];
-		e_type = enum_module_type m path pos;
+		e_type = mk_mono();
 	}
 
 let mk_abstract m path pos name_pos =

+ 1 - 1
src/core/tPrinting.ml

@@ -528,7 +528,7 @@ module Printer = struct
 			"d_doc",s_doc en.e_doc;
 			"e_meta",s_metadata en.e_meta;
 			"e_params",s_type_params en.e_params;
-			"e_type",s_tdef "\t" en.e_type;
+			"e_type",s_type_kind en.e_type;
 			"e_extern",string_of_bool en.e_extern;
 			"e_constrs",s_list "\n\t" (s_tenum_field (tabs ^ "\t")) (PMap.fold (fun ef acc -> ef :: acc) en.e_constrs []);
 			"e_names",String.concat ", " en.e_names

+ 1 - 1
src/core/tType.ml

@@ -314,7 +314,7 @@ and tenum = {
 	mutable e_using : (tclass * pos) list;
 	mutable e_restore : unit -> unit;
 	(* do not insert any fields above *)
-	e_type : tdef;
+	e_type : t;
 	mutable e_extern : bool;
 	mutable e_constrs : (string , tenum_field) PMap.t;
 	mutable e_names : string list;

+ 1 - 1
src/core/texpr.ml

@@ -492,7 +492,7 @@ module Builder = struct
 		let t =
 			match resolve_typedef mt with
 			| TClassDecl c -> TType(class_module_type c,[])
-			| TEnumDecl e -> TType(e.e_type,[])
+			| TEnumDecl e -> e.e_type
 			| TAbstractDecl a -> TType(abstract_module_type a [],[])
 			| _ -> die "" __LOC__
 		in

+ 2 - 12
src/typing/typeloadModule.ml

@@ -132,20 +132,11 @@ module ModuleLevel = struct
 				let path = make_path name priv d.d_meta p in
 				if Meta.has (Meta.Custom ":fakeEnum") d.d_meta then raise_typing_error "@:fakeEnum enums is no longer supported in Haxe 4, use extern enum abstract instead" p;
 				let e = {
-					e_path = path;
-					e_module = m;
-					e_pos = p;
-					e_name_pos = (pos d.d_name);
+					(mk_enum m path p (pos d.d_name)) with
 					e_doc = d.d_doc;
 					e_meta = d.d_meta;
-					e_params = [];
-					e_using = [];
-					e_restore = (fun () -> ());
 					e_private = priv;
 					e_extern = List.mem EExtern d.d_flags;
-					e_constrs = PMap.empty;
-					e_names = [];
-					e_type = enum_module_type m path p;
 				} in
 				if not e.e_extern then check_type_name name d.d_meta;
 				decls := (TEnumDecl e, decl) :: !decls;
@@ -535,8 +526,7 @@ module TypeLevel = struct
 		) (!constructs);
 		e.e_names <- List.rev !names;
 		e.e_extern <- e.e_extern;
-		e.e_type.t_params <- e.e_params;
-		e.e_type.t_type <- mk_anon ~fields:!fields (ref (EnumStatics e));
+		unify ctx (TType(enum_module_type e !fields,[])) e.e_type p;
 		if !is_flat then e.e_meta <- (Meta.FlatEnum,[],null_pos) :: e.e_meta;
 		if Meta.has Meta.InheritDoc e.e_meta then
 			delay ctx PConnectField (fun() -> InheritDoc.build_enum_doc ctx e);

+ 1 - 2
src/typing/typerBase.ml

@@ -210,8 +210,7 @@ let type_module_type ctx t p =
 			let t_tmp = class_module_type c in
 			mk (TTypeExpr (TClassDecl c)) (TType (t_tmp,[])) p
 		| TEnumDecl e ->
-			let types = (match tparams with None -> Monomorph.spawn_constrained_monos (fun t -> t) e.e_params | Some l -> l) in
-			mk (TTypeExpr (TEnumDecl e)) (TType (e.e_type,types)) p
+			mk (TTypeExpr (TEnumDecl e)) e.e_type p
 		| TTypeDecl s ->
 			let t = apply_typedef s (List.map (fun _ -> spawn_monomorph ctx p) s.t_params) in
 			DeprecationCheck.check_typedef (create_deprecation_context ctx) s p;