Automatic int/float casting not working?

BlitzMax Forums/Brucey's Modules/Automatic int/float casting not working?

BlitzSupport(Posted 2016) [#1]
Code similar to this used to work in ye olde BlitzMax, but doesn't in NG. Seems like it's being overly harsh here (stripped down from real-world code):

Type Player

	Field x:Float
	Field y:Float
	
	Function Create:Player (x:Int, y:Int)
	
		Local p:Player = New Player

		p.x = x
		p.y = y

		Return p

	End Function

End Type

Local player1:Player = Player.Create (100.0, 100.0)


This produces:

Compile Error: Unable to find overload for create(Float,Float). Argument #1 is "Float" but declaration is "Int".


Not sure if this is intentional or not, but, going by the BlitzMax docs, this should be allowed...


Type conversions

The following type conversions are performed automatically by BlitzMax when necessary - for example, when assigning an expression to a variable, or when passing an expression to a function:

Source type - Target type

Integer - Floating point, String
Floating point - Integer, String




LT(Posted 2016) [#2]
Guess you didn't get the memo. :) This is a result of the overloading methods feature that was added to NG. There is a -w flag that is supposed to suppress this error and give a warning instead.


BlitzSupport(Posted 2016) [#3]
Or, to put it another way:



Don't make me Int () all of these! (And that's just one line!)


BlitzSupport(Posted 2016) [#4]
Just saw your post, LT! How the heck would you apply that? This is like applying SuperDominatrixStrict!


LT(Posted 2016) [#5]
bmk -w ...from the command line. I'm not sure if the option is available in MaxIDE, but it might have been added.


Derron(Posted 2016) [#6]
It was added to https://github.com/bmx-ng/maxide.git (program - developer options)

For Linux you could get the newest IDE build:
https://github.com/GWRon/BMXNG-Packs
Didn't have had the time for Win32/Win64(if possible) builds of the IDE. Just made that pack because some people complained that they miss a compile-guide for my game (and how hard it is to get BlitzMax for free).


bye
Ron


RustyKristi(Posted 2016) [#7]
Yes, this would be confusing for new users to NG as well. Always set -w for the win ;-)


BlitzSupport(Posted 2016) [#8]
Hmm, the latest bmx-ng MaxIDE quietly dies on me after the splash screen, on Win7-64.

I noticed that some conversions work, so I guess this is just the way for 'unintentional overloading' now... can't say I'll enjoy casting every single parameter! :/


Derron(Posted 2016) [#9]
You just could widen the initial function...

So if a function expects ints but you sometimes pass floats.. you could adjust the function to accept floats and cast to int in this function (if really needed).

If maxide dies... check if the cfg file contains fontsizes with "," ... if so this is the reason.

Bye
Ron


BlitzSupport(Posted 2016) [#10]
Thanks, Ron/all, I'll look into all this. At least I know the reason for it, anyway.


GW(Posted 2016) [#11]
Note that the current NG-maxide on github is incompatible with the current blitzmax-NG on github. I posted some of the reasons here http://www.blitzbasic.com/Community/posts.php?topic=106389