I have had an odd problem in a VO X# system and have tracked it down to an ASort call that is failing. I have not so far been able to pin down the problem. I am sorting an array of 2-element arrays and it is sorting by comparing the first element of each of those sub-arrays. I think there are better ways of doing what the code is trying to do but, although the data has a fair bit of duplication, sorting should still work.
I made a small X# WinForms app, VO dialect, and replaced the programs.prg with the following code for testing:
Code: Select all
USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
USING System.Windows.Forms
USING TestFWXS
[STAThread] ;
FUNCTION Start() AS VOID
LOCAL T, S AS ARRAY
LOCAL I AS DWORD
T := {{1,27},{2,6},{1,27},{2,6},{1,27},{2,6},{1,27},{2,6},{1,27},{2,6},{1,27},{2,6},{1,27},{2,6},{1,28},{2,3},{1,28},{2,3},{1,27},{2,6},{1,27},{2,6}}
FOR I := 1 UPTO ALen(T)
S := ASize(AClone(T), I)
ASort(S, , , {|x, y| x[1] <= y[1]})
NEXT
RETURN
It is complaining that the comparer defined in the code block is faulty. It seems to fail with 17 or more elements. I will try over the weekend to debug it with the GitHub code for ASort to see if I can refine it further.System.ArgumentException
HResult=0x80070057
Message=Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. IComparer: 'XSharp.RT.ArraySortComparer'.
Source=mscorlib
StackTrace:
at System.Collections.Generic.IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(Object comparer)
at System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer)
at System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer)
at XSharp.__Array.Sort(Int32 startIndex, Int32 count, IComparer`1 comparer)
at XSharp.RT.Functions.ASort(__Array aTarget, __Usual nStart, __Usual nCount, __Usual cbOrder)
at TestFWXS.Exe.Functions.Start() in C:\Users\XVJBONNE\source\repos\LabPro\TestFWXS\Program.prg:line 17
Any suggestions?
John Bonnett

