bcc
bcc copied to clipboard
Visibility and initialization problem with Globals
SuperStrict
Framework BRL.Blitz
Local x:T[] = T2.b
DebugStop
Type T
Global a:T = New T
End Type
Type T2
Global b:T[] = [T.a]
End Type
This code should result in x containing one valid T object at the time of the DebugStop. Instead, it contains a null pointer.
SuperStrict
Framework BRL.Blitz
Local x:T[] = T2.b
DebugStop
Type T2
Global b:T[] = [T.a]
End Type
Type T
Global a:T = New T
End Type
And this code should not compile at all. Vanilla responds to this with "Compile error: Identifier 'a' not found", because in vanilla, Globals are only visible "below"/"behind" (in terms of code lines) the point at which they are declared. This applies when trying to access a Type's Globals from another Type, like in the example above, but it also applies at top level - the following should not compile either:
Global b:Int = a
Global a:Int = 3
Accessing a Type's Globals from top level however always works regardless of code order, presumably because the Type scope is accessed by name and the Type itself is visible everywhere:
Global x:Int = T.a
Type T
Global a:Int = 5
End Type
Unfortunately, vanilla is a mess in this regard and it gets weirder than that: The inverse of the above does not seem to work at all:
Global x:Int = 5
Type T
Global a:Int = x
End Type
whereas this works again:
Global x:Int = 5
Type T
Function F()
Global a:Int = x
End Function
End Type
Constants behave differently yet... I don't know how far you'd want to go to make NG compatible with vanilla. But I would suggest addressing at least the first three code examples given in this post, since those can lead to hard to find bugs otherwise.