Browse Source

define UInt to Int instead of @:to Int so variance is possible (closes #2718)

Simon Krajewski 11 years ago
parent
commit
14cd5ea204
2 changed files with 21 additions and 2 deletions
  1. 2 2
      std/UInt.hx
  2. 19 0
      tests/unit/issues/Issue2718.hx

+ 2 - 2
std/UInt.hx

@@ -31,7 +31,7 @@
 	The unsigned Int type is only defined for Flash9 and C#.
 	Simulate it for other platforms.
 **/
-abstract UInt(Int) from Int {
+abstract UInt(Int) from Int to Int {
 
 	@:op(A + B) private static inline function add(a:UInt, b:UInt):UInt {
 		return a.toInt() + b.toInt();
@@ -214,7 +214,7 @@ abstract UInt(Int) from Int {
 		return Std.string(toFloat());
 	}
 
-	@:to private inline function toInt():Int {
+	private inline function toInt():Int {
 		return this;
 	}
 

+ 19 - 0
tests/unit/issues/Issue2718.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+import unit.Test;
+
+class Issue2718 extends Test {
+	function test() {
+		var testMap = new Map();
+		var x0:UInt = 0;
+		var x1:UInt = 1;
+		var x2:UInt = 2;
+
+		testMap[x0] = "0";
+		testMap[x1] = "1";
+		testMap[x2] = "2";
+
+		eq("0", testMap[x0]);
+		eq("1", testMap[x1]);
+		eq("2", testMap[x2]);
+	}
+}