-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
GDScript: warns that a class variable is unused while it actually is #23207
Comments
Does the unused error show up if you try to read from them as well? |
@aaronfranke yes, I read from them further down but I think the parser is unable to tell. |
Well, this is not a bug, it's the same as #22206. It's in the same file but not in the same class (which is the purpose of the warning). I'll probably disable this by default because it doesn't make sense for classes used only as a data structure. |
Still happens in Godot 3.1 alpha3
How would you recognize such classes? |
I won't, I'll just disable the warning by default. If you think it's useful you can turn it on and disable only for some scripts. |
@vnen would it be possible to have it on just for variables beginning with |
It's possible but it might be confusing because for function arguments it's the opposite: starting with |
@vnen function arguments start with |
|
@aaronfranke yeah, I realized that. What I mean is that we just shot ourselves in the foot choosing a convention which already steps over another and prevents going further xD (At least if we consider not doing it because it's confusing) |
Although following the rest of the industry means that variables or bindings started with and underscope means it is 'unused' after declaration, either used as an unused 'hole' in an argument list or used for documentation purposes as the unused return of some expression. Many languages even bake the convention into the compiler itself to do precisely what is proposed here (to both signify a purposefully unused argument or to silence an 'unused return from function/expression' warning/error). In all of those languages that I can recall a function name/binding starting with an underscore is not held or checked to these conventions but is rather just a normal function name, used to traditionally signify a private function in one of them but not held to that otherwise. |
So no chance to check for member vars usage then? |
If they were private (if GDScript had a concept of private) sure, but in general I couldn't see how that would be possible. |
@OvermindDL1 get list of members, pick those starting with |
@Zylann An issue with that though is that a class can have fields that are not used internally but only used externally, so you'd have to do a whole-program-analysis for it, and considering scripts can be dynamically loaded then that's impossible. I personally use many classes as C-like structs, pure data storage and no functionality. |
@OvermindDL1 this is the point of the underscore. Just like the convention in unused arguments (already in use), they are a convention the parser can use. In member vars, it can be used to indicate privateness, which means the parser could ignore the case of external access. |
I'm getting an unused class variable warning with the following snippet on commit 6607c3c: onready var preloader := $ResourcePreloader as ResourcePreloader
onready var bounce_sounds := [
preloader.get_resource("bounce.0"),
preloader.get_resource("bounce.1"),
preloader.get_resource("bounce.2"),
preloader.get_resource("bounce.3"),
] Is this related since I'm using it just below in another member variable? |
What's the current status of this issue? Is there a plan to deal with it? Perhaps bump to 4.0?
The warning is still enabled in the current master. Should the warning be disabled by default? |
Godot 3.1 alpha 1
I made a subclass in my script just to hold a few variables together, however all of them produce an "unused" warning. Of course they are not used within that subclass (because it has no functions), but I use them like "public" variables elsewhere in the enclosing script, so the warning is just adding false positive noise.
The text was updated successfully, but these errors were encountered: