Browse Source

Add test for #9946 (#10044)

* Add test for #9946

* Actually check attribute from haxe

* Remove untyped

* Fix test
Rudy Ges 4 years ago
parent
commit
74cda8fbda

+ 2 - 0
tests/unit/native_cs/hxcs_build.txt

@@ -18,6 +18,8 @@ M haxe.test.GenericHelper
 C haxe.test.GenericHelper
 M haxe.test.StaticAndInstanceClash
 C haxe.test.StaticAndInstanceClash
+M haxe.test.AttrWithNullType
+C haxe.test.AttrWithNullType
 M NoPackage
 C NoPackage
 end modules

+ 17 - 0
tests/unit/native_cs/src/haxe/test/AttrWithNullType.cs

@@ -0,0 +1,17 @@
+using System;
+
+namespace haxe.test {
+	[MyAttr(null)]
+	public class AttrWithNullType {}
+
+	[MyAttr(typeof(AttrWithNullType))]
+	public class AttrWithNonNullType {}
+
+	public class MyAttrAttribute : Attribute {
+		public bool check;
+
+		public MyAttrAttribute(System.Type t) {
+			check = (t == null);
+		}
+	}
+}

+ 30 - 0
tests/unit/src/unit/issues/Issue9946.hx

@@ -0,0 +1,30 @@
+package unit.issues;
+
+#if cs
+import cs.system.Attribute;
+import haxe.test.AttrWithNullType;
+import haxe.test.AttrWithNonNullType;
+import haxe.test.MyAttrAttribute;
+#end
+
+class Issue9946 extends unit.Test {
+	#if cs
+	function test() {
+		eq(hasNullArg(cs.Lib.toNativeType(AttrWithNullType)), true);
+		eq(hasNullArg(cs.Lib.toNativeType(AttrWithNonNullType)), false);
+	}
+
+	static function hasNullArg(cls:cs.system.Type):Null<Bool> {
+		var attributes = @:privateAccess new Array(Attribute.GetCustomAttributes(cls));
+
+		for (attr in attributes) {
+			if (Std.isOfType(attr, MyAttrAttribute)) {
+				var a:MyAttrAttribute = cast attr;
+				return a.check;
+			}
+		}
+
+		return null;
+	}
+	#end
+}