[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: _Compare, passes array to single value compare.. Bug?


_compare is used during sorting, it will only pass the same datatype, but if it is a variant and the datatype is an array of the datatype it should not be getting passed into the _compare. It look like an actual but to me. It fails if an attempt to pass any other data type is passed.

Pretty sure that an array of Crmpit[] is not the same as crmpit when it comes to a sort.

On 7/10/24 15:39, Bruce Steers wrote:
You need to account for it.

Ii may be an array[] but it is still a Variant as Variant can be anything so it is passed.

If Object.Type(rvalue) = "Crmpit[]" Then

Or maybe
If rvalue Is Crmpit[] Then

Respects
BruceS

On Wed, 10 Jul 2024, 16:35 Brian G, <brian@xxxxxxxxxxxxxxxx> wrote:

    When I have an object called  myobject with a _compare() the compiler
    passes both myobject and myobject[] to the function. But does not
    pass
    either when both are myobject[]. Not sure what the correct
    behavior is,
    but it seems incorrect to pass [] to a single myobject.

    Anybody know what it should happen,  or do we have to guard against
    receiving an [], what should be the correct return value when we
    get an [].

    Sample script

    --------------------------------------------------------------------------

    #!/usr/bin/env gbs3
    'Auto Generated Script 07/10/2024 15:15:32.628 Version (3.19.90)
    #Script Startup="Main"
    #Script Version="0.0.1"
    class cmpit
    ' Gambas class file
    Public value As Variant = Null
    Public Sub _new(newvalue As Variant)
         value = newvalue
    End

    Public Sub _compare(rvalue As Variant) As Integer
         If value = rvalue.value Then Return 0
         If value > rvalue.value Then Return 1
         Return -1
    End
    End class

    ' Gambas module file
    Public Sub Main()
         Print "Hello world"
         Dim a As New Cmpit(9)
         Dim b As New Cmpit(10)
         Dim c As Variant = a
         Dim e As New Cmpit[10]
         For i As Integer = 0 To e.Max
             e[i] = New Cmpit(9)
         Next
         Print Str(a = b), Str(c = a)
         Print Str(a = e)
    End

    _________________________________________________________________-

-- ~~~~ Brian

--
~~~~ Brian

Attachment: OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


Follow-Ups:
Re: _Compare, passes array to single value compare.. Bug?Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
References:
_Compare, passes array to single value compare.. Bug?Brian G <brian@xxxxxxxxxxxxxxxx>
Re: _Compare, passes array to single value compare.. Bug?Bruce Steers <bsteers4@xxxxxxxxx>