Crash Accessing Field from Function inside Method

Archives Forums/BlitzMax Bug Reports/Crash Accessing Field from Function inside Method

Otus(Posted 2009) [#1]
Runs in debug mode, crashes without error in release mode after printing "in".

SuperStrict
Framework BRL.StandardIO

Type TTest
	
	Field s:String = "hello world"
	
	Method Emit()
		Function Out()
			Print s
		End Function
		
		Print "in"
		Out 
		Print "out"
	End Method
	
End Type

Local t:TTest = New TTest
t.Emit



grable(Posted 2009) [#2]
Its not supposed to work either ;)

A function inside another function or method, is still a global function, its just not visible outside.
The reason it sometimes work, is because the Self pointer is still on the stack somewhere.

Pass Self as a parameter instead, i know not as good looking, but at least it wont hang at random intervals hehe


Brucey(Posted 2009) [#3]
Yeah. It doesn't make sense that "s" would have scope inside a global function.

It should probably throw a compiler error.


plash(Posted 2009) [#4]
Yeah. It doesn't make sense that "s" would have scope inside a global function.
But I could easily see how someone would think of it in that inheritable way.


Otus(Posted 2009) [#5]
Yeah, it's probably not supposed to work, but oddly it does in debug mode. Something similar works in some languages, especially the more functional-programming-oriented ones. Anyway, this should probably give an error at compile time.


marksibly(Posted 2009) [#6]
Hi,

Yes, the compiler should be picking this up - 's' shouldn't be visible to the function.