Browse Source

[cs] Do not convert string to any other IConvertible type; Correctly deal with Decimal and Int64. Closes #2668

Cauê Waneck 11 years ago
parent
commit
562ff93a86
2 changed files with 33 additions and 2 deletions
  1. 22 2
      std/cs/internal/Runtime.hx
  2. 11 0
      tests/unit/issues/Issue2668.hx

+ 22 - 2
std/cs/internal/Runtime.hx

@@ -98,13 +98,33 @@ import cs.system.Type;
 				if (t1 == t2)
 				if (t1 == t2)
 					return v1c.Equals(v2c);
 					return v1c.Equals(v2c);
 
 
+				if (t1 == System.TypeCode.String || t2 == System.TypeCode.String)
+					return false;
+
 				switch(t1)
 				switch(t1)
 				{
 				{
+					case System.TypeCode.Decimal:
+						return v1c.ToDecimal(null) == v2c.ToDecimal(null);
 					case System.TypeCode.Int64:
 					case System.TypeCode.Int64:
 					case System.TypeCode.UInt64:
 					case System.TypeCode.UInt64:
-						return v1c.ToUInt64(null) == v2c.ToUInt64(null);
+						if (t2 == System.TypeCode.Decimal)
+							return v1c.ToDecimal(null) == v2c.ToDecimal(null);
+						else
+							return v1c.ToUInt64(null) == v2c.ToUInt64(null);
 					default:
 					default:
-						return v1c.ToDouble(null) == v2c.ToDouble(null);
+						switch(t2)
+						{
+							case System.TypeCode.Decimal:
+								return v1c.ToDecimal(null) == v2c.ToDecimal(null);
+							case System.TypeCode.Int64:
+							case System.TypeCode.UInt64:
+								if (t2 == System.TypeCode.Decimal)
+									return v1c.ToDecimal(null) == v2c.ToDecimal(null);
+								else
+									return v1c.ToUInt64(null) == v2c.ToUInt64(null);
+							default:
+								return v1c.ToDouble(null) == v2c.ToDouble(null);
+						}
 				}
 				}
 			}
 			}
 
 

+ 11 - 0
tests/unit/issues/Issue2668.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue2668 extends unit.Test
+{
+	public function test()
+	{
+		var a:Dynamic = 1.5;
+		var b:Dynamic = "s";
+		f(a == b);
+	}
+}