ソースを参照

Skip abstract impl classes when applying addGlobalMetadata (#11546)

* [typer] don't add meta to abstract impl through addGlobalMetadata

* [tests] add test for #11545
Rudy Ges 1 年間 前
コミット
eb37ceeb86

+ 4 - 1
src/typing/typeloadModule.ml

@@ -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

+ 30 - 0
tests/misc/projects/Issue11545/Macro.hx

@@ -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 - 0
tests/misc/projects/Issue11545/Main.hx

@@ -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 - 0
tests/misc/projects/Issue11545/compile.hxml

@@ -0,0 +1,2 @@
+--macro Macro.initMacro()
+--run Main

+ 3 - 0
tests/misc/projects/Issue11545/compile.hxml.stdout

@@ -0,0 +1,3 @@
+Macro.hx:21: main
+Macro.hx:21: _new
+Main.hx:4: abc