bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Byte + Byte, different result than in BlitzMax (legacy)

Open GWRon opened this issue 1 year ago • 2 comments

See this code:

SuperStrict
Framework Brl.StandardIO
Import Brl.Reflection

Local a:Byte = 250
Local b:Byte = 10
Print a+b

Local arr:Object = [a + b]
Print TTypeID.ForObject(arr).Name()

Local i:Int = 255:byte + 1:Byte
Print i

In legacy it prints:

260
Int[]
256

In NG it prints:

260
Byte[]
0

So while NGs behaviour is reasonable it is at least not "backwards compatible". Cannot say if we should be backwards compatible there - or not.

In Legacy any "byte +- byte" becomes an "int" while in NG the result seems to be "preserving" the "biggest primitive type" in the formula.

GWRon avatar Nov 22 '24 15:11 GWRon

@HurryStarfish pointed out, that NG differentiates between "ByteVar + ByteVar" (250+10 = 260:Int) and "byteValue + byteValue" (255:Byte + 1:Byte = 0:Byte). So this can at least be seen as bug?

GWRon avatar Nov 22 '24 16:11 GWRon

The fact that it differs from legacy BlitzMax certainly makes this a bug, it is a breaking change in behaviour. Bytes/Shorts should be promoted to Ints consistently.

Local a:Byte = 250
Local b:Byte = 10
Print a + b

does output the correct result.

HurryStarfish avatar Nov 23 '24 01:11 HurryStarfish