[Mono-bugs] [Bug 442257] System.Array.Sort produces wrong results

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Nov 10 06:46:34 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=442257

User alan.mcgovern at gmail.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=442257#c2





--- Comment #2 from Alan McGovern <alan.mcgovern at gmail.com>  2008-11-10 04:46:33 MST ---
Created an attachment (id=251016)
 --> (https://bugzilla.novell.com/attachment.cgi?id=251016)
throw an exception when the comparer is broken.

// This should provide reversed order (Greatest first)
return ((ix > iy ? 1 : 0));

No, it won't. This is a broken IComparer. If you want greatest first you should
implement either of the following:

*  iy.CompareTo (ix)
* -ix.CompareTo (iy)

You've broken one of the rules of IComparers there by writing a comparer which
returns a different value depending on the order of the arguments. The rule is:

* x.CompareTo (y) == -y.CompareTo (x)

// This should throw an exception!
return ((ix > iy ? 1 : -1));

This is an invalid IComparer aswell. I'm attaching a patch to implement the
exception. There are probably more cases which need to be checked, but I'm not
100% familiar with the code, so I may have missed them.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list