Browse Source

properly type haxe.rtti.Meta.getMeta, so proper code is generated for optional field access (closes #5389)

Dan Korostelev 9 years ago
parent
commit
1c24209b23
2 changed files with 25 additions and 2 deletions
  1. 8 2
      std/haxe/rtti/Meta.hx
  2. 17 0
      tests/unit/src/unit/issues/Issue5389.hx

+ 8 - 2
std/haxe/rtti/Meta.hx

@@ -21,9 +21,15 @@
  */
  */
 package haxe.rtti;
 package haxe.rtti;
 
 
+private typedef MetaObject = {
+	?fields:Dynamic<Dynamic<Null<Array<Dynamic>>>>,
+	?statics:Dynamic<Dynamic<Null<Array<Dynamic>>>>,
+	?obj:Dynamic<Null<Array<Dynamic>>>,
+}
+
 /**
 /**
 	An API to access classes and enums metadata at runtime.
 	An API to access classes and enums metadata at runtime.
-	
+
 	@see <http://haxe.org/manual/cr-rtti.html>
 	@see <http://haxe.org/manual/cr-rtti.html>
 **/
 **/
 class Meta {
 class Meta {
@@ -51,7 +57,7 @@ class Meta {
 		#end
 		#end
 	}
 	}
 
 
-	private static function getMeta(t:Dynamic):Dynamic
+	private static function getMeta(t:Dynamic):MetaObject
 	{
 	{
 #if (java || cs || php || (flash && as3))
 #if (java || cs || php || (flash && as3))
 		var ret = Reflect.field(t, "__meta__");
 		var ret = Reflect.field(t, "__meta__");

+ 17 - 0
tests/unit/src/unit/issues/Issue5389.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+
+@test
+private class C {
+}
+
+private class C1 {
+	@test function f() {}
+}
+
+class Issue5389 extends unit.Test {
+	function test() {
+		eq(0, Reflect.fields(haxe.rtti.Meta.getFields(C)).length);
+		eq(0, Reflect.fields(haxe.rtti.Meta.getStatics(C)).length);
+		eq(0, Reflect.fields(haxe.rtti.Meta.getType(C1)).length);
+	}
+}