From 5f450da638cd4518ee4993bcee03db43387e5ad6 Mon Sep 17 00:00:00 2001 From: jeberle Date: Tue, 20 May 2008 10:03:30 +0000 Subject: fixed #681 Changes in the Comparator.cs, called when using "==". And recompiled scalaruntime.dll. Perhaps the code can be better (simplifying the condition), but it works. --- src/dotnet-library/scala/runtime/Comparator.cs | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/dotnet-library') 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; } -- cgit v1.2.3