-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static variables are not maintained correctly #992
Comments
Looking into this now. |
What happens is that the Module load functions call their respective class' load function and both Derived1 and Derived2 (obviously) call their parent's (Base) load function, which resets Basically this means that any side effect on static member initialization will be evaluated multiple times (as many times as you have sublclasses). Proposed fix is auto generating a static |
On a sidenote, string literals are constructed after class loads which leads to crashes if you try to use one in your static member initialization. However, I don't think reversing global variable initialization and class load order is wise, since you may initialize a variable that depends on the class' static members. I will see if there is some way to only reverse the order between (string) literals and class loads. |
@thomasfanell |
Consider this example, where everything works as expected:
Base.ooc
Derived1.ooc
Derived2.ooc
main.ooc
Now, if we instead comment out
d1
andd2
inmain.ooc
and uncomment the creation ofDerived1
andDerived2
in their respective files, we getInstance count = 1
. That is, the static variable is re-initialized for every instance.The text was updated successfully, but these errors were encountered: