Browse Source

Make haxe.DynamicAccess.set return the given value (closes #3517)

Dan Korostelev 10 years ago
parent
commit
95e74ebc00
2 changed files with 8 additions and 3 deletions
  1. 6 1
      std/haxe/DynamicAccess.hx
  2. 2 2
      tests/unit/src/unitstd/haxe/DynamicAccess.unit.hx

+ 6 - 1
std/haxe/DynamicAccess.hx

@@ -57,10 +57,15 @@ abstract DynamicAccess<T>(Dynamic<T>) from Dynamic<T> to Dynamic<T> {
 
 		If the structure contains the given key, its value will be overwritten.
 
+		Returns the given value.
+
 		If `key` is null, the result is unspecified.
 	**/
 	@:arrayAccess
-	public inline function set(key:String, value:T):Void Reflect.setField(this, key, value);
+	public inline function set(key:String, value:T):T {
+		Reflect.setField(this, key, value);
+		return value;
+	}
 
 	/**
 		Tells if the structure contains a specified `key`.

+ 2 - 2
tests/unit/src/unitstd/haxe/DynamicAccess.unit.hx

@@ -1,9 +1,9 @@
 var map = new haxe.DynamicAccess();
 map.exists("foo") == false;
 map.get("foo") == null;
-map["foo"] =  1;
+(map["foo"] = 1) == 1;
 map.set("bar", 2);
-map.set("baz", 3);
+map.set("baz", 3) == 3;
 map.exists("foo") == true;
 map.exists("bar") == true;
 map.exists("baz") == true;