Forráskód Böngészése

Macro defined modules vs direct loading of types using it (#11740)

* [tests] add failing test demonstrating the issue

* Flush between actx.classes loading

* [tests] Update failing test

But why was it 3 before?

* Rebase

* Add expected output to test
Rudy Ges 5 hónapja
szülő
commit
2451699c76

+ 4 - 1
src/compiler/compiler.ml

@@ -310,7 +310,10 @@ let do_type ctx mctx actx display_file_dot_path =
 		com.callbacks#run com.error_ext com.callbacks#get_after_init_macros;
 		com.callbacks#run com.error_ext com.callbacks#get_after_init_macros;
 		run_or_diagnose ctx (fun () ->
 		run_or_diagnose ctx (fun () ->
 			if com.display.dms_kind <> DMNone then DisplayTexpr.check_display_file tctx cs;
 			if com.display.dms_kind <> DMNone then DisplayTexpr.check_display_file tctx cs;
-			List.iter (fun cpath -> ignore(tctx.Typecore.g.Typecore.do_load_module tctx cpath null_pos)) (List.rev actx.classes);
+			List.iter (fun cpath ->
+				ignore(tctx.Typecore.g.Typecore.do_load_module tctx cpath null_pos);
+				Typecore.flush_pass tctx.g PBuildClass "actx.classes"
+			) (List.rev actx.classes);
 			Finalization.finalize tctx;
 			Finalization.finalize tctx;
 		);
 		);
 	end with TypeloadParse.DisplayInMacroBlock ->
 	end with TypeloadParse.DisplayInMacroBlock ->

+ 1 - 1
tests/misc/projects/Issue11004/build.hxml.stdout

@@ -1 +1 @@
-Bar.hx:27: @:storedTypedExpr 3 computed this_ident as: foo.bar
+Bar.hx:27: @:storedTypedExpr 1 computed this_ident as: foo.bar

+ 6 - 0
tests/misc/projects/Issue11740/Baz.hx

@@ -0,0 +1,6 @@
+import foo.Foo;
+
+class Baz {
+	function baz(data:foo.FooData) {}
+}
+

+ 17 - 0
tests/misc/projects/Issue11740/Macro.macro.hx

@@ -0,0 +1,17 @@
+import haxe.macro.Context;
+
+class Macro {
+	public static function build() {
+		trace("build FooData");
+
+		Context.defineType({
+			pos : Context.currentPos(),
+			name : "FooData",
+			pack : ["foo"],
+			kind : TDClass(),
+			fields : [],
+		});
+
+		return null;
+	}
+}

+ 5 - 0
tests/misc/projects/Issue11740/Main.hx

@@ -0,0 +1,5 @@
+import foo.Foo;
+
+function main() {
+	trace(Baz);
+}

+ 2 - 0
tests/misc/projects/Issue11740/compile1.hxml

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

+ 2 - 0
tests/misc/projects/Issue11740/compile1.hxml.stdout

@@ -0,0 +1,2 @@
+Macro.macro.hx:5: build FooData
+Main.hx:4: Class<Baz>

+ 3 - 0
tests/misc/projects/Issue11740/compile2.hxml

@@ -0,0 +1,3 @@
+-main Main
+Baz
+--interp

+ 2 - 0
tests/misc/projects/Issue11740/compile2.hxml.stdout

@@ -0,0 +1,2 @@
+Macro.macro.hx:5: build FooData
+Main.hx:4: Class<Baz>

+ 4 - 0
tests/misc/projects/Issue11740/foo/Foo.hx

@@ -0,0 +1,4 @@
+package foo;
+
+@:build(Macro.build())
+class Foo {}