-
Notifications
You must be signed in to change notification settings - Fork 13
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
"_hasBeenSet" private bool should not be generated if unused #52
Comments
Thanks, this is a reasonable request. I just haven't ended up encountering it because I've never used e.g. It looks like you've done some digging and understand how the generator works, would you be interested in submitting a PR? I'd be happy to accept it and build/publish a new version. (I've stopped using GodotOnReady in 4.0 because it doesn't work anymore, but glad to do small things like this for continued 3.x usage.) |
/// <param name="path">
/// The path that will be loaded when the node is ready. If not set, a property is generated
/// with [Export], so the path can be set in the Godot editor.
/// </param> |
Interesting, this could be the cause for quite some confusion on my side regarding the workings of Export/OnReadyGet. Great the documentation could be improved this way! (And my code simplified a bit.)
It is in fact the null check that's interesting for me. I have built small utility system to auto-generate in-editor warnings (via _GetConfigurationWarning) for fields marked with OnReadyGet that are missing. Based on this I use Export for optional nodes/resources and OnReadyGet for mandatory ones. In doing so I can use non-nullables while guaranteeing that the null-suppressed null assignments won't shoot me in the foot at runtime.
I will open a pull request with the suggested change. |
Version 1.2.4 is now pushed with these changes. Thanks again! 😄 |
Currently, for an
OnReadyGet
like this:the generated code looks like that:
The code responsible for that is this here:
GodotOnReady/src/GodotOnReady.Generator/Additions/OnReadyGetResourceAddition.cs
Lines 21 to 27 in f1a47c0
But
_hasBeenSetMyTexture
is never used. (I noticed this because I got several CS0414 warnings when compiling.)It would only be used if the generator had to generate the assignment by itself as in here:
GodotOnReady/src/GodotOnReady.Generator/Additions/OnReadyGetResourceAddition.cs
Lines 48 to 55 in f1a47c0
I couldn't find any documentation regarding the possible usage of
_hasBeenSet
outside the generated code (i.e. by the user) and cannot imagine a sensible use case.Therefore I suggest to only generate
_hasBeenSet
ifIsGeneratingAssignment
is set, so that it is only generated if it is actually used.The text was updated successfully, but these errors were encountered: