Feature Request - Strict option for types

BlitzMax Forums/BlitzMax Programming/Feature Request - Strict option for types

Robert(Posted 2005) [#1]
I don't know if I am the only one, but I often end up typing in something like

Local list=New TList

By mistake, when it should be:

Local list:TList=New TList

The first version still compiles under BlitzMAX, and will work with the list functions, but of course is outside of the scope of the garbage collector which may lead to leaks.

I would like a compiler switch, similar to Strict which would throw an error when trying to compile the first version, unless explicit casting is used.

For example:

StrictTypes

'This is okay
Local list:TList=New TList

'This is okay since explicit casting is being used
'This won't actually compile at the moment, you have to do something like "Local list=Int(Byte Ptr(New TList))" instead
Local list=Int(New TList)

'This reports an error
Local list=New TLIst



ziggy(Posted 2005) [#2]
This option will make imposible to make any 'variable' type declaration, and it may make BlitzMax loose a bit of its polimorphism. Think about it...


Robert(Posted 2005) [#3]
and it may make BlitzMax loose a bit of its polimorphism.


No, something like:

Local something:BaseType=New DerivedType

Would still be fine. The only thing that would be ruled out would be automatic Int <-> Object conversions. They could still be done, but with explicit casting.

I realise that Mark was trying to make things easier for beginners, but I think that in the end it actually complicates the matter.


teamonkey(Posted 2005) [#4]
Yeah, I see what you mean.

Local list=New TList is exactly the same as Local list:Int=New TList, which isn't necessarily what you expect.

Personally, I'd force Strict mode so that you have to add the type to everything (even Ints) when you're initialising them.