-
-
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
Fix analyzer pushing SHADOWED_VARIABLE warning for members shadowed in subclass #98873
base: master
Are you sure you want to change the base?
Fix analyzer pushing SHADOWED_VARIABLE warning for members shadowed in subclass #98873
Conversation
modules/gdscript/tests/scripts/analyzer/warnings/local_variable_shadows_base_member.gd
Outdated
Show resolved
Hide resolved
aae9172
to
d4881bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. It would be great to check the grammar in documentation and warning messages.
@@ -0,0 +1,7 @@ | |||
class_name ShadowingBase | |||
|
|||
const base_const_member = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test cast for it in the shadowning.gd
script.
@@ -5809,8 +5809,7 @@ void GDScriptAnalyzer::validate_call_arg(const List<GDScriptParser::DataType> &p | |||
#ifdef DEBUG_ENABLED | |||
void GDScriptAnalyzer::is_shadowing(GDScriptParser::IdentifierNode *p_identifier, const String &p_context, const bool p_in_local_scope) { | |||
const StringName &name = p_identifier->name; | |||
GDScriptParser::DataType base = parser->current_class->get_datatype(); | |||
GDScriptParser::ClassNode *base_class = base.class_type; | |||
const GDScriptParser::DataType current_class_type = parser->current_class->get_datatype(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: this isn't used until line 5841. It's recommended to declare variables as close to the first use as possible, if it doesn't affect anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it above:
if (p_in_local_scope) {
GDScriptParser::ClassNode *base_class = current_class_type.class_type;
this way it is accessible for base_class
and native_base_class
(defined later).
…n subclasses This fixes a bug in the analyzer where it did not push the SHADOWED_VARIABLE_BASE_CLASS warning for members shadowed by variable in subclass. It does this by comparing the class which contains the shadowed member with the class containing the variable, and pushing SHADOWED_VARIABLE only if the classes are the same. Additionally, SHADOWED_VARIABLE_BASE_CLASS can take an extra symbol which helps to specify the line for non native base class.
8d0aee7
to
413490c
Compare
This fixes #74395. It does this by comparing the class which contains the shadowed member with the class containing the variable, and pushing the
SHADOWED_VARIABLE
warning only if the classes are the same, otherwise theSHADOWED_VARIABLE_BASE_CLASS
warning is pushed.Additionally,
SHADOWED_VARIABLE_BASE_CLASS
can now take an extra symbol which helps to specify the line for non native base class.Comments and docs have been updated to highlight that these warnings are related to shadowed members in the concerning class instead of just shadowed variables.