I am not sure if a class should be allowed to compile like this, but right now it does.
When the variables are parsed and added to the parent class, their value expression is invoked. If it can not be invoked the variable gets it's default value.
Invoking functions works, no matter if the function is declared after it is used. This does not work for variables.
class TestBaseClass { string m_Variable = m_Fnc(); string m_Variable2 = m_Variable3; string m_Variable3 = "Hi there!"; string m_Fnc() { return "Hello World"; }; };
Produces:
SCRIPT : string m_Variable = 'Hello World' SCRIPT : string m_Variable2 = '' SCRIPT : string m_Variable3 = 'Hi there!'
Swapping the load order to this:
class TestBaseClass { string m_Variable = m_Fnc(); string m_Variable3 = "Hi there!"; string m_Variable2 = m_Variable3; string m_Fnc() { return "Hello World"; }; };
Produces:
SCRIPT : string m_Variable = 'Hello World' SCRIPT : string m_Variable2 = 'Hi there!' SCRIPT : string m_Variable3 = 'Hi there!'
The behavior is not surprising, given the way enscript currently works. What could be done is:
- Not allow non-const expressions as assignments for class field declarations
- Push variables, where the assingment expression could not be executed, due to unknown functions/variables, to a list and keep pushing it back until everything else is resolved. If all class members are loaded and it's still not resolved throw a compile error that says "unknown variable/function xxx on line x" to indicate that the line is faulty. Just ignoring the assignment expression (as it is right now) is not really verbose.