Explorar el Código

[jvm] still apply `haxe.root` to top-level `@:native`

closes #10280
Simon Krajewski hace 4 años
padre
commit
696d8b53c3

+ 1 - 4
src/generators/genjvm.ml

@@ -2818,10 +2818,7 @@ module Preprocessor = struct
 		List.exists (fun mt -> snd (t_infos mt).mt_path = snd m.m_path) m.m_types
 
 	let check_path mt =
-		(* don't rewrite if there's an explicit @:native *)
-		if Meta.has Meta.Native mt.mt_meta then
-			()
-		else if mt.mt_private && has_primary_type mt.mt_module then begin
+		if mt.mt_private && has_primary_type mt.mt_module && not (Meta.has Meta.Native mt.mt_meta) then begin
 			let m = mt.mt_module in
 			let pack = match fst m.m_path with
 				| [] -> ["haxe";"root"]

+ 40 - 0
tests/misc/java/projects/Issue10280/Main.hx

@@ -0,0 +1,40 @@
+import haxe.macro.Compiler;
+import haxe.macro.Context;
+import haxe.macro.Expr;
+import haxe.macro.Expr.Field;
+class Main {
+    static function main() OldClass.define();
+}
+
+#if !macro
+@:build(OldClass.build())
+#end
+@:native("NewClass")
+class OldClass {
+	#if !macro
+	public function new() {};
+	#end
+
+	macro public static function define():Expr return macro new OldClass();
+
+	macro static function build():Array<Field>
+	{
+		var defined = false;
+
+		Context.onAfterTyping(_ -> {
+			if (defined) return;
+
+			Context.defineType(
+				macro class NewClass {
+					public function new() {}
+				}
+			);
+
+			Compiler.exclude('OldClass');
+
+			defined = true;
+		});
+
+		return null;
+	}
+}

+ 3 - 0
tests/misc/java/projects/Issue10280/compile.hxml

@@ -0,0 +1,3 @@
+-main Main
+--jvm jvm.jar
+-cmd java -jar jvm.jar

BIN
tests/misc/java/projects/Issue10280/jvm.jar