Skip to content

Commit

Permalink
Macro defined modules vs direct loading of types using it (#11740)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
kLabz authored Feb 15, 2025
1 parent 5fe6110 commit 2451699
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
run_or_diagnose ctx (fun () ->
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;
);
end with TypeloadParse.DisplayInMacroBlock ->
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue11004/build.hxml.stdout
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions tests/misc/projects/Issue11740/Baz.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import foo.Foo;

class Baz {
function baz(data:foo.FooData) {}
}

17 changes: 17 additions & 0 deletions tests/misc/projects/Issue11740/Macro.macro.hx
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/misc/projects/Issue11740/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import foo.Foo;

function main() {
trace(Baz);
}
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11740/compile1.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-main Main
--interp
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11740/compile1.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Macro.macro.hx:5: build FooData
Main.hx:4: Class<Baz>
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue11740/compile2.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Main
Baz
--interp
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11740/compile2.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Macro.macro.hx:5: build FooData
Main.hx:4: Class<Baz>
4 changes: 4 additions & 0 deletions tests/misc/projects/Issue11740/foo/Foo.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package foo;

@:build(Macro.build())
class Foo {}

0 comments on commit 2451699

Please sign in to comment.