Returning Some Int64's From Methods With Return Type Auto Gives Wrong Value

I have just come across an odd issue involving Int64’s and Auto. Returning an Int64 value “-5365523934200603553” from a method with return type set to Auto gives the wrong value. It should return the same Int64 but instead returns “-753837915773215649” which is only bit 32 set.

I can’t seem to find a way around it as I need to return a few different types from that method that get put into a Xojo.Core.Dictionary. Has anyone seen this before? Have any workarounds? Much appreciated.

// Create 2 functions each returning the same Int64 but one with return type as Auto.

Public Function GetInt64AsInt64() as Int64
    dim i as Int64 = -5365523934200603553
    return i
End Function


Public Function GetInt64AsAuto() as Auto
    dim i as Int64 = -5365523934200603553
    return i
End Function

dim Int64AsInt64 as Int64 = GetInt64AsInt64
dim Int64AsAuto as Int64 = GetInt64AsAuto

// Int64AsInt64 <> Int64AsAuto

Feedback Report with sample project attached: <https://xojo.com/issue/60582> (Not sure why it won’t let me set it to something other than Beta Bug)

What if you assign it to an auto first ?
ie

Dim Int64AsInt64 As Int64 = GetInt64AsInt64
Dim a As Auto = GetInt64AsAuto
If Xojo.Introspection.GetType(a) = GetTypeInfo(Int64) Then
  Break
Else
  Break
End If
Dim Int64AsAuto As Int64 = a

Break

Odd as it might seem this seems to work so there seems to be something funky about how it compiles that code where its not assigned to an auto first

a bug in bug reporting
<https://xojo.com/issue/59816>

[quote=491447:@Norman Palardy]What if you assign it to an auto first ?
ie

Dim Int64AsInt64 As Int64 = GetInt64AsInt64
Dim a As Auto = GetInt64AsAuto
If Xojo.Introspection.GetType(a) = GetTypeInfo(Int64) Then
  Break
Else
  Break
End If
Dim Int64AsAuto As Int64 = a

Break

Odd as it might seem this seems to work so there seems to be something funky about how it compiles that code where its not assigned to an auto first

a bug in bug reporting
<https://xojo.com/issue/59816>[/quote]

Hmm, this still seems to fail for me. I’m on macOS.

Nice bug, doesn’t seem to be anything to do with methods, looks like the first bit after the sign is getting flipped for some reason but only in 64bit as it works fine in 32bit (on windows at least):

[code]Dim i As Int64 = -5365523934200603553
Dim a As Auto = i

Dim d As Int64 = a - i

system.DebugLog(i.ToBinary(64))
system.DebugLog(CType(a, Int64).ToBinary(64))
system.DebugLog(d.ToBinary(64))

Break[/code]

And a bit clearer here:

[code]Dim i As Int64 = -4611686018427387904
Dim a As Auto = i

Dim d As Int64 = a - i

system.DebugLog(i.ToBinary(64))
system.DebugLog(CType(a, Int64).ToBinary(64))
system.DebugLog(d.ToBinary(64))

Break[/code]

I spend longer than I wish to admit thinking it was my fault, just couldn’t fathom how one of my numbers was coming out so funky down the line. At first I thought it was the BinaryStream I was reading, or I got the endianness wrong or 100 other reasons. Once I worked my way up I found “-753837915773215649”, put it in my calculator and saw it was just bit 32 set. Knew something was wrong.

Bitwise operations in older versions silently failed mixing 32 and 64 bit, even pure 64bit got silently (real) crazy. The compiler did not do a proper 64bit native math and more. Maybe related, but propagated to guts of the framework.

In 2016r3 Xojo for Windows this DESTROYS the answer, not just do it wrong.

Dim i64a, i64b, i64c As int64

i64b = -3
i64c = -2
i64a = i64b or i64c // Yeah, I know about the bitwise class, but it should not be needed here

System.DebugLog i64a.ToBinary + " " + i64b.ToBinary + " " + i64c.ToBinary