Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip abstract impl classes when applying addGlobalMetadata #11546

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ module TypeLevel = struct
let init_class ctx_m c d p =
if ctx_m.m.is_display_file && DisplayPosition.display_position#enclosed_in (pos d.d_name) then
DisplayEmitter.display_module_type ctx_m (match c.cl_kind with KAbstractImpl a -> TAbstractDecl a | _ -> TClassDecl c) (pos d.d_name);
TypeloadCheck.check_global_metadata ctx_m c.cl_meta (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None;
(match c.cl_kind with
| KAbstractImpl _ -> ()
| _ -> TypeloadCheck.check_global_metadata ctx_m c.cl_meta (fun m -> c.cl_meta <- m :: c.cl_meta) c.cl_module.m_path c.cl_path None
);
let herits = d.d_flags in
List.iter (fun (m,_,p) ->
if m = Meta.Final then begin
Expand Down
30 changes: 30 additions & 0 deletions tests/misc/projects/Issue11545/Macro.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if macro
import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr;

class Macro {
public static function initMacro() {
Compiler.addGlobalMetadata("Main", "@:build(Macro.instrumentFields())", true, true, false);
}

static function instrumentFields():Null<Array<Field>> {
var fields:Array<Field> = Context.getBuildFields();
for (field in fields) {
switch (field.kind) {
case FFun(f):
if (f.expr == null) {
continue;
}
switch (f.expr.expr) {
case EBlock(exprs):
exprs.unshift(macro trace($v{field.name}));
case _:
}
case _:
}
}
return fields;
}
}
#end
12 changes: 12 additions & 0 deletions tests/misc/projects/Issue11545/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Main {
static function main() {
var name = new ImageName("abc");
trace(name);
}
}

abstract ImageName(String) {
public function new(name:String) {
this = name;
}
}
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11545/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--macro Macro.initMacro()
--run Main
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue11545/compile.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Macro.hx:21: main
Macro.hx:21: _new
Main.hx:4: abc
Loading