-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
SHADOWED_VARIABLE warning is unclear for derived classes #74395
Comments
stumbled over this, thanks to this issue I am no longer questioning my sanity |
looks like the same issue also for function parameters
|
It does shadow it, within
However, it's kind of partial shadowing because it seems like
Being strict/consistent shouldn't
I'd say the above is a separate issue. |
It should not be recognized as a shadow, it is a local typed parameter of type string. |
Can you explain why you just downvote without any comments? As I said, the function argument This is simply a problem of the parser implementation, and you are not ready to fix it. |
In 4.x, variables and functions share a common scope. When you access a function without parentheses, you get it as a |
Thanks for the explanation 👍
You say it shares, so it will hold both a variable and a function with the same name? From my perspective, this is a self-made issue by allow the plain function name as a Callable, sure this has potential to conflict with variable names. I'm just thinking loud ;) |
No. Let me explain in more detail. 3.xIn 3.x, variables, functions and signals live in separate scopes. We have warnings
4.xIn 4.x, functions and signals became first class values. You can get a function as a
This is a common approach. JavaScript and other languages also do not have separate scopes for variables and functions. I find it more obvious to have just one scope for all identifier types, since there are already several locality scopes (global, class and block). Why have several identifiers of the same name that mean different things?
Some languages use sigils for identifiers of different types. For example in PHP you can have a function |
All right, thanks for diving deeper in this topic to give me a better understanding. |
I have been working on a PR for this and I wonder which of the following solutions, if any, would be preferred. I have attached a screenshot for the result of each solution. |
I don't think we need a new warning type. The comments, the messags and the documentation all say the same thing: godot/modules/gdscript/gdscript_warning.h Lines 56 to 57 in 2ad452a
godot/modules/gdscript/gdscript_warning.cpp Lines 62 to 67 in 2ad452a
godot/doc/classes/ProjectSettings.xml Lines 563 to 568 in 2ad452a
However, godot/modules/gdscript/gdscript_analyzer.cpp Lines 5841 to 5873 in 2ad452a
So we should:
|
Godot version
v4.0.stable.official [92bee43]
System information
Steam OS Holo, Steam Deck
Issue description
The SHADOWED_VARIABLE warning is unclear when the shadowed variable belongs to a user-defined base class.
Base.gd
Derived.gd
The use of
name
inBase
triggers a very clear SHADOWED_VARIABLE_BASE_CLASS warning:However, the use of
inherited
inDerived
triggers a SHADOWED_VARIABLE warning that does not reference the base class:To demonstrate how confusing this could be, I've deliberately set things up here such that
shadowed
triggers a warning pointing to the same line number, despite shadowing a different variable defined in a different class:Steps to reproduce
Run the minimal reproduction project.
Minimal reproduction project
ShadowedVariables.zip
The text was updated successfully, but these errors were encountered: