Răsfoiți Sursa

works but I hate it

Simon Krajewski 5 luni în urmă
părinte
comite
0008ff9ad3

+ 1 - 0
src/context/typecore.ml

@@ -99,6 +99,7 @@ type typer_globals = {
 	mutable macros : ((unit -> unit) * typer) option;
 	mutable module_check_policies : (string list * module_check_policy list * bool) list;
 	mutable global_using : (tclass * pos) list;
+	global_import : resolution_list;
 	(* Indicates that Typer.create() finished building this instance *)
 	mutable complete : bool;
 	mutable type_hints : (module_def_display * pos * t) list;

+ 6 - 1
src/typing/typeload.ml

@@ -203,8 +203,13 @@ let load_type_def ctx p t =
 		(* If there's a sub-type, there's no reason to look in our module or its imports *)
 		if t.tsub <> None then raise Not_found;
 		find_type_in_current_module_context ctx t.tpackage tname
-	with Not_found ->
+	with Not_found -> try
 		load_type_def' ctx t.tpackage t.tname tname p
+	with Error { err_message = Module_not_found mpath } as exc when mpath = (t.tpackage,t.tname) -> try
+		let mt,_ = ctx.g.global_import#find_type_import t.tname in
+		mt
+	with Not_found ->
+		raise exc
 
 let generate_args_meta com cls_opt add_meta args =
 	let values = List.fold_left (fun acc ((name,p),_,_,_,eo) -> match eo with Some e -> ((name,p,NoQuotes),e) :: acc | _ -> acc) [] args in

+ 24 - 21
src/typing/typer.ml

@@ -201,28 +201,29 @@ let resolve_against_expected_enum ctx i =
 	| Some mt ->
 		loop mt
 
+let resolve_import ctx mode res p =
+	ImportHandling.mark_import_position ctx res.r_pos;
+	match res.r_kind with
+	| RTypeImport(_,mt) ->
+		AKExpr (type_module_type ctx mt p)
+	| RClassFieldImport(_,c,cf) ->
+		let e = type_module_type ctx (TClassDecl c) p in
+		field_access ctx mode cf (FHStatic c) e p
+	| RAbstractFieldImport(_,a,c,cf) ->
+		let et = type_module_type ctx (TClassDecl c) p in
+		let inline = match cf.cf_kind with
+			| Var {v_read = AccInline} -> true
+			|  _ -> false
+		in
+		let fa = FieldAccess.create et cf (FHAbstract(a,extract_param_types a.a_params,c)) inline p in
+		AKField fa
+	| REnumConstructorImport(_,en,ef) ->
+		enum_field_access ctx en ef mode p res.r_pos
+	| RWildcardPackage _ | RLazy _ | RClassStatics _ | REnumStatics _ ->
+		assert false
+
 let rec type_ident_raise ctx i p mode with_type =
-	let resolve res =
-		ImportHandling.mark_import_position ctx res.r_pos;
-		match res.r_kind with
-		| RTypeImport(_,mt) ->
-			AKExpr (type_module_type ctx mt p)
-		| RClassFieldImport(_,c,cf) ->
-			let e = type_module_type ctx (TClassDecl c) p in
-			field_access ctx mode cf (FHStatic c) e p
-		| RAbstractFieldImport(_,a,c,cf) ->
-			let et = type_module_type ctx (TClassDecl c) p in
-			let inline = match cf.cf_kind with
-				| Var {v_read = AccInline} -> true
-				|  _ -> false
-			in
-			let fa = FieldAccess.create et cf (FHAbstract(a,extract_param_types a.a_params,c)) inline p in
-			AKField fa
-		| REnumConstructorImport(_,en,ef) ->
-			enum_field_access ctx en ef mode p res.r_pos
-		| RWildcardPackage _ | RLazy _ | RClassStatics _ | REnumStatics _ ->
-			assert false
-	in
+	let resolve res = resolve_import ctx mode res p in
 	match i with
 	| "true" ->
 		let acc = AKExpr (mk (TConst (TBool true)) ctx.t.tbool p) in
@@ -382,6 +383,8 @@ and type_ident ctx i p mode with_type =
 				AKExpr {e with etype = (extract_param_type t)}
 			end else
 				raise Not_found
+		with Not_found -> try
+			resolve_import ctx mode (ctx.g.global_import#resolve i) p
 		with Not_found ->
 			if ctx.f.untyped then begin
 				if i = "__this__" then

+ 3 - 2
src/typing/typerEntry.ml

@@ -114,7 +114,7 @@ let load_unit ctx =
 		| TEnumDecl en ->
 			(match snd en.e_path with
 			| "Unit" ->
-				ctx.m.import_resolution#add (module_type_resolution mt None null_pos);
+				ctx.g.global_import#add (module_type_resolution mt None null_pos);
 			| _ -> ())
 		| _ -> ()
 	) m.m_types
@@ -148,6 +148,7 @@ let create com macros =
 			debug_delayed = [];
 			retain_meta = Common.defined com Define.RetainUntypedMeta;
 			global_using = [];
+			global_import = new resolution_list ["global"];
 			complete = false;
 			type_hints = [];
 			load_only_cached_modules = false;
@@ -190,7 +191,7 @@ let create com macros =
 	load_string ctx;
 	load_std ctx;
 	load_any ctx;
-	(* load_unit ctx; *)
+	load_unit ctx;
 	load_array ctx;
 	load_enum_tools ctx;
 	ignore(TypeloadModule.load_module ctx (["haxe"],"Exception") null_pos);

+ 0 - 0
tests/unit/src/unitstd/haxe/Unit.unit.hx.disabled → tests/unit/src/unitstd/haxe/Unit.unit.hx