Procházet zdrojové kódy

[eval] create fake instance prototypes for @:coreType abstracts

closes #8778
Simon Krajewski před 6 roky
rodič
revize
8204d4bd42

+ 3 - 0
src/macro/eval/evalPrototype.ml

@@ -341,6 +341,9 @@ let add_types ctx types ready =
 			DynArray.add fl_static (create_static_prototype ctx mt);
 		| TAbstractDecl a ->
 			DynArray.add fl_static (create_static_prototype ctx mt);
+			(* Create a fake instance prototype for coreType abstracts in case something inspects them (#8778). *)
+			if Meta.has Meta.CoreType a.a_meta then
+				DynArray.add fl_instance (create_instance_prototype ctx {null_class with cl_path = a.a_path})
 		| _ ->
 			()
 	) new_types;

+ 13 - 0
tests/unit/src/unit/issues/Issue8778.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue8778 extends unit.Test {
+	function test() {
+		eq("haxe.macro.Position", runMacro("foo"));
+	}
+
+	macro static function runMacro(e:haxe.macro.Expr) {
+		var c = Type.getClass(e.pos);
+		var fields = Type.getInstanceFields(c);
+		return macro $v{Type.getClassName(c)};
+	}
+}