Browse Source

Specify Reflect.copy(null) (#8448)

* specify Reflect.copy(null)

* fix eval
Aleksandr Kuzmenko 6 years ago
parent
commit
7ba3a01189

+ 1 - 0
src/macro/eval/evalStdLib.ml

@@ -1813,6 +1813,7 @@ module StdReflect = struct
 	)
 	)
 
 
 	let copy = vfun1 (fun o -> match vresolve o with
 	let copy = vfun1 (fun o -> match vresolve o with
+		| VNull -> VNull
 		| VObject o -> VObject { o with ofields = Array.copy o.ofields }
 		| VObject o -> VObject { o with ofields = Array.copy o.ofields }
 		| VInstance vi -> vinstance {
 		| VInstance vi -> vinstance {
 			ifields = Array.copy vi.ifields;
 			ifields = Array.copy vi.ifields;

+ 2 - 2
std/Reflect.hx

@@ -195,9 +195,9 @@ extern class Reflect {
 
 
 		This is only guaranteed to work on anonymous structures.
 		This is only guaranteed to work on anonymous structures.
 
 
-		If `o` is null, the result is unspecified.
+		If `o` is null, the result is `null`.
 	**/
 	**/
-	public static function copy<T>( o : T ) : T;
+	public static function copy<T>( o : Null<T> ) : Null<T>;
 
 
 	/**
 	/**
 		Transform a function taking an array of arguments into a function that can
 		Transform a function taking an array of arguments into a function that can

+ 1 - 1
std/cpp/_std/Reflect.hx

@@ -97,7 +97,7 @@ class Reflect {
 		return untyped __global__.__hxcpp_anon_remove(o,field);
 		return untyped __global__.__hxcpp_anon_remove(o,field);
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
 		if (o==null) return null;
 		if (o==null) return null;
 		if(untyped o.__GetType()==ObjectType.vtString ) return o;
 		if(untyped o.__GetType()==ObjectType.vtString ) return o;
 		if(untyped o.__GetType()==ObjectType.vtArray )
 		if(untyped o.__GetType()==ObjectType.vtArray )

+ 2 - 1
std/cs/_std/Reflect.hx

@@ -160,8 +160,9 @@ import cs.system.reflection.*;
 		return false;
 		return false;
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T
+	public static function copy<T>( o : Null<T> ) : Null<T>
 	{
 	{
+		if(o == null) return null;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for( f in Reflect.fields(o) )
 		for( f in Reflect.fields(o) )
 			Reflect.setField(o2,f,Reflect.field(o,f));
 			Reflect.setField(o2,f,Reflect.field(o,f));

+ 2 - 1
std/flash/_std/Reflect.hx

@@ -116,7 +116,8 @@
 		return true;
 		return true;
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
+		if(o == null) return null;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for( f in Reflect.fields(o) )
 		for( f in Reflect.fields(o) )
 			Reflect.setField(o2,f,Reflect.field(o,f));
 			Reflect.setField(o2,f,Reflect.field(o,f));

+ 1 - 1
std/hl/_std/Reflect.hx

@@ -122,7 +122,7 @@ class Reflect {
 	}
 	}
 
 
 	@:hlNative("std","obj_copy")
 	@:hlNative("std","obj_copy")
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
 		return null;
 		return null;
 	}
 	}
 
 

+ 2 - 1
std/java/_std/Reflect.hx

@@ -134,8 +134,9 @@ import java.Boot;
 		return (Std.is(o, DynamicObject) && (o : DynamicObject).__hx_deleteField(field));
 		return (Std.is(o, DynamicObject) && (o : DynamicObject).__hx_deleteField(field));
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T
+	public static function copy<T>( o : Null<T> ) : Null<T>
 	{
 	{
+		if(o == null) return null;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for( f in Reflect.fields(o) )
 		for( f in Reflect.fields(o) )
 			Reflect.setField(o2,f,Reflect.field(o,f));
 			Reflect.setField(o2,f,Reflect.field(o,f));

+ 2 - 1
std/js/_std/Reflect.hx

@@ -95,7 +95,8 @@
 		return true;
 		return true;
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
+		if(o == null) return null;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for( f in Reflect.fields(o) )
 		for( f in Reflect.fields(o) )
 			Reflect.setField(o2,f,Reflect.field(o,f));
 			Reflect.setField(o2,f,Reflect.field(o,f));

+ 1 - 1
std/jvm/_std/Reflect.hx

@@ -164,7 +164,7 @@ class Reflect {
 		return (cast o : jvm.DynamicObject)._hx_deleteField(field);
 		return (cast o : jvm.DynamicObject)._hx_deleteField(field);
 	}
 	}
 
 
-	public static function copy<T>(o:T):T {
+	public static function copy<T>(o:Null<T>):Null<T> {
 		if (!Jvm.instanceof(o, jvm.DynamicObject)) {
 		if (!Jvm.instanceof(o, jvm.DynamicObject)) {
 			return null;
 			return null;
 		}
 		}

+ 2 - 1
std/lua/_std/Reflect.hx

@@ -121,7 +121,8 @@ import lua.Boot;
 		return true;
 		return true;
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
+		if(o == null) return null;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for( f in Reflect.fields(o) )
 		for( f in Reflect.fields(o) )
 			Reflect.setField(o2,f,Reflect.field(o,f));
 			Reflect.setField(o2,f,Reflect.field(o,f));

+ 2 - 1
std/neko/_std/Reflect.hx

@@ -102,7 +102,8 @@
 		return $objremove(o,$fasthash(field.__s));
 		return $objremove(o,$fasthash(field.__s));
 	}
 	}
 
 
-	public inline static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
+		if(o == null) return null;
 		return untyped $new(o);
 		return untyped $new(o);
 	}
 	}
 
 

+ 1 - 1
std/php/_std/Reflect.hx

@@ -158,7 +158,7 @@ using php.Global;
 		}
 		}
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
 		if (Boot.isAnon(o)) {
 		if (Boot.isAnon(o)) {
 			return Syntax.clone(o);
 			return Syntax.clone(o);
 		} else {
 		} else {

+ 2 - 1
std/python/_std/Reflect.hx

@@ -136,7 +136,8 @@ class Reflect {
 		return true;
 		return true;
 	}
 	}
 
 
-	public static function copy<T>( o : T ) : T {
+	public static function copy<T>( o : Null<T> ) : Null<T> {
+		if(o == null) return null;
 		var o2 : Dynamic = {};
 		var o2 : Dynamic = {};
 		for ( f in Reflect.fields(o) )
 		for ( f in Reflect.fields(o) )
 			Reflect.setField(o2, f, Reflect.field(o,f));
 			Reflect.setField(o2, f, Reflect.field(o,f));

+ 1 - 0
tests/unit/src/unitstd/Reflect.unit.hx

@@ -80,6 +80,7 @@ var y = Reflect.copy(x);
 Reflect.field(y, "a") == 2;
 Reflect.field(y, "a") == 2;
 Reflect.field(y, "b") == null;
 Reflect.field(y, "b") == null;
 Reflect.field(y, "c") == null;
 Reflect.field(y, "c") == null;
+Reflect.copy(null) == null;
 
 
 //compare
 //compare
 Reflect.compare(1,2) < 0;
 Reflect.compare(1,2) < 0;