diff options
author | jeberle <jeberle@epfl.ch> | 2008-05-20 10:03:30 +0000 |
---|---|---|
committer | jeberle <jeberle@epfl.ch> | 2008-05-20 10:03:30 +0000 |
commit | 5f450da638cd4518ee4993bcee03db43387e5ad6 (patch) | |
tree | ecb83a32dc98ea5d72d101db11f087a30356feb7 /src/dotnet-library | |
parent | 3d7e820e9bc7d67023949eeecedb1b6bdedf53f5 (diff) | |
download | scala-5f450da638cd4518ee4993bcee03db43387e5ad6.tar.gz scala-5f450da638cd4518ee4993bcee03db43387e5ad6.tar.bz2 scala-5f450da638cd4518ee4993bcee03db43387e5ad6.zip |
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.
Diffstat (limited to 'src/dotnet-library')
-rw-r--r-- | src/dotnet-library/scala/runtime/Comparator.cs | 31 |
1 files changed, 21 insertions, 10 deletions
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; } |