Bug? Order of operations/logic error with Objects

ac9ts

Active Member
Licensed User
Longtime User
I am writing an app where I need to search through groups of integers and I believe I found a bug. I am using a list rather than an array because I need to sort the numbers prior to doing the search. Below is the simplified code.

B4X:
Dim L As List                ' as Object
L.Initialize
L.Add(5)
L.Add(6)

Log(L.Get(1)-1 = L.Get(0))    '    6-1 = 5 evaluates true
Log(L.Get(0) = L.Get(1)-1)    '    5 = 6-1 evaluates false <<<<<< Bug??

Dim C(2) As Object
C(0)=5
C(1)=6

Log(C(1)-1 = C(0))            '    6-1 = 5 evaluates true       
Log(C(0) = C(1)-1)            '    5 = 6-1 evaluates false <<<<<< Bug??

Dim C1(2) As Int
C1(0)=5
C1(1)=6

Log(C1(1)-1 = C1(0))        '    6-1 = 5 evaluates true       
Log(C1(0) = C1(1)-1)        '    5 = 6-1 evaluates true
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The compiler doesn't know the type of each element in the list. In the first case the first value is a number so it treats the second value as a number too and does an numeric comparison.

In the second case it doesn't know the comparison type required. The result is that it compares an int to double (with an object comparison) and returns false.

You need to help the compiler in this case:
B4X:
Dim i1 As Int = L.Get(1) - 1
Log(i1 = L.Get(0))
 
Top