Function in method bug

BlitzMax Forums/BlitzMax Bug Reports/Function in method bug

Type thing

	Field v#=99
	
	Method do()
	
		func()
	
		Function func()
			Notify v
		EndFunction
	
	EndMethod
	

EndType


t:thing=New thing
t.do()


Type thing

	Field v#=99
	
	Method do()
	
		func(Self)
	
		Function func(ASelf:thing)
			Notify Aself.v
		EndFunction
	
	EndMethod
	

EndType


t:thing=New thing
t.do()


Hi,

The compiler should be generating an error here, but basically you can't do this - inner functions cannot access the fields/locals of outer scopes.

yeah I tried this a while back. It's a no go (at the moment, fingers crossed). I used to use this technique a lot in Delphi.

I don't mind one way or another, but it would help if the compiler generated an error. This was causing some random crashes before I figured out what was wrong.

It could, at least, throw a warning when nesting a function in a method. Nesting a function in a function does not produce this bug. I supose it is to the lose of instance context on functions.

I'm surprised that the BlitzMax compiler never produce warnings.