bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Suggestion: add (optional?) compile warnings for casted return values #558

Open GWRon opened 3 years ago

GWRon commented 3 years ago
Function MyCustomCompareFunction:Int(o1:Object, o2:Object)
  Return TMy(o1).longValue - TMy(o2).longValue
End Function

If you are not aware of "longValue" being of type long (eg by refactoring from int to long) this issue might sneek in unseen. (the issue in this case is a potential "roll over" if the difference is bigger or smaller than the integer limits)

So maybe optionally inform the developer via a "warning", that you cast unseen (here from long to int).

HurryStarfish commented 3 years ago

Not just return values - this would apply to any potentially "lossy" assignment.

GWRon commented 3 years ago

Hmm but doesn't it warn already when passing eg. a double as a float in functions ?

Function MyFunc(f:Float)
End Function

MyFunc( sin(10) )

isn't this "similar" ?

HurryStarfish commented 3 years ago

Yes, that's part of it. But while it gives a warning when passing a Double to a Float parameter, it doesn't do that for many other cases, such as Float to Int, UInt to Int, etc. And it only does that for function/method parameters. It also doesn't give warnings when such implicit conversions happen elsewhere, e.g. Local f:Float = someDoubleVariable.