Browse Source

allow array access on Map again (fixed issue #1601)

Simon Krajewski 12 years ago
parent
commit
bad811e412
2 changed files with 15 additions and 1 deletions
  1. 6 1
      std/Map.hx
  2. 9 0
      tests/unit/TestBasetypes.hx

+ 6 - 1
std/Map.hx

@@ -80,7 +80,7 @@ abstract Map< K, V > (IMap< K, V > ) {
 		
 		If [key] is null, the result is unspecified.
 	**/
-	public inline function get(key:K) return this.get(key);
+	@:arrayAccess public inline function get(key:K) return this.get(key);
 	
 	/**
 		Returns true if [key] has a mapping, false otherwise.
@@ -124,6 +124,11 @@ abstract Map< K, V > (IMap< K, V > ) {
 		return this.toString();
 	}
 	
+	@:arrayAccess @:noCompletion public inline function arrayWrite(k:K, v:V):V {
+		this.set(k, v);
+		return v;
+	}
+	
 	@:to static inline function toStringMap(t:IMap < String, V > ):StringMap<V> {
 		return new StringMap<V>();
 	}

+ 9 - 0
tests/unit/TestBasetypes.hx

@@ -270,6 +270,15 @@ class TestBasetypes extends Test {
 		t( h.remove(1) );
 		f( h.remove(1) );
 	}
+	
+	function testMap() {
+		var i = new Map();
+		i[1] = 0;
+		var x = 1;
+		i[x++] += 4;
+		eq(x, 2);
+		eq(i[1], 4);
+	}
 
 	function testObjectKeyword() {
 		// new is a keyword in Haxe