Static local variable - parser bug?

Archives Forums/BlitzMax Bug Reports/Static local variable - parser bug?

BlitzSupport(Posted 2015) [#1]
Just noting for reference...

I was reading this article and started playing with static locals, believing they were do-able in Max (which it seems they are), but accidentally stumbled across what looks like a bug...

This works (by FlameDuck):

Function staticTest()
	Global myVar:Int
	
	myVar:+1
	Print myVar
EndFunction

staticTest
staticTest
staticTest
staticTest
staticTest
staticTest


... but this doesn't, yet appears functionally the same to me (the Print is irrelevant):

Function Testing ()

	Global lo:Int

	lo + lo + 1		' Identifier 'lo' not found!

'	lo:+1			' Works!

	Print lo		' No error!
	
End Function

Testing
Testing
Testing



Floyd(Posted 2015) [#2]
You stated in the Blitz font thread that you use 10 point type. Maybe you should increase that.

	lo + lo + 1		' Identifier 'lo' not found!

Compiler Error Identifier 'lo' not found is certainly misleading.


BlitzSupport(Posted 2015) [#3]
Hi Floyd, reckon I'm missing something here, or you are!

That's all "L-Oh" as far as I can see...


H&K(Posted 2015) [#4]
Function Testing ()

	Global lo:Int = lo + lo + 1		' Duplicate Identifier lo


	Print lo		' No error!
	
End Function

Testing
Testing
Testing
It defiantly thinks there are two different lo's


Floyd(Posted 2015) [#5]
Hi James,

Based on

myVar:+1
appears functionally the same to me
lo + lo + 1

I assumed it was simply a typo, intended to be lo = lo + 1.


H&K(Posted 2015) [#6]
@Floyd,

Assume you're right, doesn't "Identifier 'lo' not found!" seem a wired error for that typo?

Edit. I thought it was a typo as well though ;)


Brucey(Posted 2015) [#7]
It's probably looking for a function called "lo" : lo (+lo +1)


Floyd(Posted 2015) [#8]
It's probably looking for a function called "lo" : lo (+lo +1)

This version is suitable for BlitzMax and Blitz3D
Function Testing ()

	Local lo
	lo + lo + 1
	
End Function

BlitzMax says identifier 'lo' not found.
Blitz3D says function 'lo' not found.


col(Posted 2015) [#9]
Using Strict gives me 'Expression of type 'Int' cannot be invoked', which is not so bad in that at least its accurate when compared with the variable not being found error.


BlitzSupport(Posted 2015) [#10]
OK, so 'lo' was a poor choice... I'd started with 'hi' and 'lo' and stripped it down from there!

Seems like it should have worked, though.


Floyd(Posted 2015) [#11]
Hey James, the curiosity is killing me! What is the first line of code supposed to do? Considering the commented out second line I thought "add 1 to lo".
It looks like you hit one key too many, presumably Shift. ( + and = on same key )
Anyway, that was the point of my wise-ass hint about a bigger font, so you could see the mistyped character.
	lo + lo + 1		' Identifier 'lo' not found!

'	lo:+1			' Works!



H&K(Posted 2015) [#12]
My guess its not supposed to do anything, its an error.

What I thought was being asked was why Identifier 'lo' not found!, and the next line was just to show it did exist.


Henri(Posted 2015) [#13]
Hi,

I believe that the correct error is 'Expression of a type 'Int' cannot be invoked' which is seen when the statement is wrapped in parenthesis like
(lo + 2 + 1)

-Henri


H&K(Posted 2015) [#14]
@Henri,

I don't think it is, as
	Global lo:Int = lo + lo + 1		' Duplicate Identifier lo
Shows it defiantly thinks there are two lo's.
Brucey is probably right, and its one value one Function


Who was John Galt?(Posted 2015) [#15]
The error may or may not be meaningful, but you don't expect 'lo + lo + 1' to compile, do you? There's no '=' (or implied '=' as when using 'lo:+1')


BlitzSupport(Posted 2015) [#16]
Oh, carp!! Now I see it!

lo = lo + 1


Doh, works fine! Gah!


BlitzSupport(Posted 2015) [#17]
I'll let everyone have a chuckle and then quietly bury this thread.


Who was John Galt?(Posted 2015) [#18]
Love it! Could have forgiven you if it was a Monday. ;)