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

allow `@:eager` on typedefs to follow them early (closes #4825)

Simon Krajewski 9 роки тому
батько
коміт
f8d6198d2f

+ 1 - 0
src/syntax/ast.ml

@@ -65,6 +65,7 @@ module Meta = struct
 		| Deprecated
 		| DirectlyUsed
 		| DynamicObject
+		| Eager
 		| Enum
 		| EnumConstructorParam
 		| Event

+ 1 - 0
src/typing/common.ml

@@ -466,6 +466,7 @@ module MetaInfo = struct
 		| Deprecated -> ":deprecated",("Mark a type or field as deprecated",[])
 		| DirectlyUsed -> ":directlyUsed",("Marks types that are directly referenced by non-extern code",[Internal])
 		| DynamicObject -> ":dynamicObject",("Used internally to identify the Dynamic Object implementation",[Platforms [Java;Cs]; UsedOn TClass; Internal])
+		| Eager -> ":eager",("Forces typedefs to be followed early",[UsedOn TTypedef])
 		| Enum -> ":enum",("Defines finite value sets to abstract definitions",[UsedOn TAbstract])
 		| EnumConstructorParam -> ":enumConstructorParam",("Used internally to annotate GADT type parameters",[UsedOn TClass; Internal])
 		| Event -> ":event",("Automatically added by -net-lib on events. Has no effect on types compiled by Haxe",[Platform Cs; UsedOn TClassField])

+ 12 - 7
src/typing/typeload.ml

@@ -3281,13 +3281,18 @@ let init_module_type ctx context_init do_init (decl,p) =
 			if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
 			tt
 		| _ ->
-			let r = exc_protect ctx (fun r ->
-				if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
-				r := (fun() -> tt);
-				tt
-			) "typedef_rec_check" in
-			delay ctx PForce (fun () -> ignore(!r()));
-			TLazy r
+			if (Meta.has Meta.Eager d.d_meta) then
+				follow tt
+			else begin
+				let f r =
+					if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
+					r := (fun() -> tt);
+					tt
+				in
+				let r = exc_protect ctx f "typedef_rec_check" in
+				delay ctx PForce (fun () -> ignore(!r()));
+				TLazy r
+			end
 		) in
 		(match t.t_type with
 		| TMono r ->

+ 6 - 0
tests/misc/projects/Issue4825/Macro.hx

@@ -0,0 +1,6 @@
+class Macro {
+    static function buildSomething() {
+        haxe.macro.Context.defineType(macro class K { });
+        return null;
+    }
+}

+ 9 - 0
tests/misc/projects/Issue4825/Main.hx

@@ -0,0 +1,9 @@
+@:genericBuild(Macro.buildSomething())
+class C<T> { }
+
+@:eager typedef T = C<String>;
+
+class Main {
+    static var k:K; // Type not found : K
+    public static function main() { }
+}

+ 2 - 0
tests/misc/projects/Issue4825/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp