Browse Source

add as global import

Simon Krajewski 5 months ago
parent
commit
5821385836
2 changed files with 15 additions and 3 deletions
  1. 12 0
      src/typing/typerEntry.ml
  2. 3 3
      tests/unit/src/unitstd/haxe/Unit.unit.hx

+ 12 - 0
src/typing/typerEntry.ml

@@ -108,6 +108,17 @@ let load_array ctx =
 	with Exit ->
 		()
 
+let load_unit ctx =
+	let m = TypeloadModule.load_module ctx (["haxe"],"Unit") null_pos in
+	List.iter (fun mt -> match mt with
+		| TEnumDecl en ->
+			(match snd en.e_path with
+			| "Unit" ->
+				ctx.m.import_resolution#add (module_type_resolution mt None null_pos);
+			| _ -> ())
+		| _ -> ()
+	) m.m_types
+
 let load_enum_tools ctx =
 	let m = TypeloadModule.load_module ctx (["haxe"],"EnumTools") null_pos in
 	match m.m_types with
@@ -179,6 +190,7 @@ let create com macros =
 	load_string ctx;
 	load_std ctx;
 	load_any ctx;
+	load_unit ctx;
 	load_array ctx;
 	load_enum_tools ctx;
 	ignore(TypeloadModule.load_module ctx (["haxe"],"Exception") null_pos);

+ 3 - 3
tests/unit/src/unitstd/haxe/Unit.unit.hx

@@ -1,9 +1,9 @@
-var u:haxe.Unit = Unit;
+var u = Unit;
 Reflect.isObject(u) == false;
 Reflect.isEnumValue(u) == true;
 Reflect.isFunction(u) == false;
-Reflect.compare(u, haxe.Unit.Unit.Unit) == 0;
-Reflect.compare(haxe.Unit.Unit.Unit, u) == 0;
+Reflect.compare(u, Unit) == 0;
+Reflect.compare(Unit, u) == 0;
 Reflect.compare(u, u) == 0;
 // Type.getClass(u) == null;
 Type.getEnum(u) == haxe.Unit;