Skip to content

Commit

Permalink
Skip abstract impl classes when applying addGlobalMetadata (#11546)
Browse files Browse the repository at this point in the history
* [typer] don't add meta to abstract impl through addGlobalMetadata

* [tests] add test for #11545
  • Loading branch information
kLabz committed Feb 5, 2024
1 parent c55da75 commit eb37cee
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
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

0 comments on commit eb37cee

Please sign in to comment.