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

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


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
>
>

Follow-Ups:
Re: _Compare, passes array to single value compare.. Bug?Brian G <brian@xxxxxxxxxxxxxxxx>
References:
_Compare, passes array to single value compare.. Bug?Brian G <brian@xxxxxxxxxxxxxxxx>