Browse Source

[flash] add flash.AnyType (closes #8549)

Dan Korostelev 6 years ago
parent
commit
dbbb9da771
3 changed files with 33 additions and 0 deletions
  1. 6 0
      src/generators/genswf9.ml
  2. 9 0
      std/flash/AnyType.hx
  3. 18 0
      tests/unit/src/unit/issues/Issue8549.hx

+ 6 - 0
src/generators/genswf9.ml

@@ -231,6 +231,8 @@ let rec type_id ctx t =
 			type_path ctx c.cl_path)
 			type_path ctx c.cl_path)
 	| TAbstract ({ a_path = [],"Null"},_) ->
 	| TAbstract ({ a_path = [],"Null"},_) ->
 		HMPath ([],"Object")
 		HMPath ([],"Object")
+	| TAbstract ({ a_path = ["flash"],"AnyType"},_) ->
+		HMAny
 	| TAbstract (a,_) when Meta.has Meta.CoreType a.a_meta ->
 	| TAbstract (a,_) when Meta.has Meta.CoreType a.a_meta ->
 		type_path ctx a.a_path
 		type_path ctx a.a_path
 	| TFun _ | TType ({ t_path = ["flash";"utils"],"Function" },[]) ->
 	| TFun _ | TType ({ t_path = ["flash";"utils"],"Function" },[]) ->
@@ -264,6 +266,8 @@ let classify ctx t =
 		KBool
 		KBool
 	| TAbstract ({ a_path = [],"Void" },_) | TEnum ({ e_path = [],"Void" },_) ->
 	| TAbstract ({ a_path = [],"Void" },_) | TEnum ({ e_path = [],"Void" },_) ->
 		KDynamic
 		KDynamic
+	| TAbstract ({ a_path = ["flash"],"AnyType" },_) ->
+		KDynamic
 	| TEnum ({ e_path = ["flash"],"XmlType"; e_extern = true },_) ->
 	| TEnum ({ e_path = ["flash"],"XmlType"; e_extern = true },_) ->
 		KType (HMPath ([],"String"))
 		KType (HMPath ([],"String"))
 	| TEnum (e,_) ->
 	| TEnum (e,_) ->
@@ -1034,6 +1038,8 @@ let rec gen_type ctx t =
 		write ctx (HGetLex t);
 		write ctx (HGetLex t);
 		List.iter (gen_type ctx) tl;
 		List.iter (gen_type ctx) tl;
 		write ctx (HApplyType (List.length tl));
 		write ctx (HApplyType (List.length tl));
+	| HMAny ->
+		write ctx (HNull)
 	| _ ->
 	| _ ->
 		write ctx (HGetLex t)
 		write ctx (HGetLex t)
 
 

+ 9 - 0
std/flash/AnyType.hx

@@ -0,0 +1,9 @@
+package flash;
+
+/**
+	This type represents the Flash `*` type, which is
+	actually the absense of type. It can be used as a
+	type parameter for `flash.Vector` to represent the
+	native `Vector.<*>` type.
+**/
+@:coreType abstract AnyType from Dynamic to Dynamic {}

+ 18 - 0
tests/unit/src/unit/issues/Issue8549.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+class Issue8549 extends unit.Test {
+	#if flash
+	function test() {
+		// can be used as a Vector type param, for type checking :-/
+		var v = new flash.Vector<String>();
+		var anyVector:Class<flash.Vector<flash.AnyType>> = flash.Vector.typeReference();
+		t(Std.is(v, anyVector));
+
+		// also assignable from/to stuff, similar to Any, just in case...
+		var v:flash.AnyType = 10;
+		eq(10, v);
+		var i:Int = v;
+		eq(10, i);
+	}
+	#end
+}