diff options
-rwxr-xr-x | lib/scalaruntime.dll | bin | 5120 -> 5632 bytes | |||
-rw-r--r-- | src/dotnet-library/scala/runtime/Comparator.cs | 31 |
2 files changed, 21 insertions, 10 deletions
diff --git a/lib/scalaruntime.dll b/lib/scalaruntime.dll Binary files differindex 86dff58dc5..f44db0628b 100755 --- a/lib/scalaruntime.dll +++ b/lib/scalaruntime.dll diff --git a/src/dotnet-library/scala/runtime/Comparator.cs b/src/dotnet-library/scala/runtime/Comparator.cs index 4a1322d49c..fb304260e3 100644 --- a/src/dotnet-library/scala/runtime/Comparator.cs +++ b/src/dotnet-library/scala/runtime/Comparator.cs @@ -22,16 +22,27 @@ namespace scala.runtime { return true; IConvertible aa = a as IConvertible; IConvertible bb = b as IConvertible; - if (aa != null && bb != null) { - if (a is Decimal || b is Decimal) - return aa.ToDecimal(null) == bb.ToDecimal(null); - if (a is Double || b is Double) - return aa.ToDouble(null) == bb.ToDouble(null); - if (a is Single || b is Single) - return aa.ToSingle(null) == bb.ToSingle(null); - if (a is Int64 || b is Int64) - return aa.ToInt64(null) == bb.ToInt64(null); - return aa.ToInt32(null) == bb.ToInt32(null); + + // We must check if a and b are realy convertible to numbers, because + // String is also an implementation of IConvertible... + // So we can avoid having "12" == 12 returning true !! + if((a is Decimal || a is Double || a is Single || a is Byte + || a is SByte || a is Int16 || a is UInt16 || a is Int32 + || a is UInt32 || a is Int64 || a is UInt64) + && (b is Decimal || b is Double || b is Single || b is Byte + || b is SByte || b is Int16 || b is UInt16 || b is Int32 + || b is UInt32 || b is Int64 || b is UInt64)){ + if (aa != null && bb != null) { + if (a is Decimal || b is Decimal) + return aa.ToDecimal(null) == bb.ToDecimal(null); + if (a is Double || b is Double) + return aa.ToDouble(null) == bb.ToDouble(null); + if (a is Single || b is Single) + return aa.ToSingle(null) == bb.ToSingle(null); + if (a is Int64 || b is Int64) + return aa.ToInt64(null) == bb.ToInt64(null); + return aa.ToInt32(null) == bb.ToInt32(null); + } } return false; } |