mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 09:31:34 +00:00
GDScript: add variable shadowing warning
(cherry picked from commit 14078fbb82)
This commit is contained in:
parent
66c1b8adc4
commit
ad1e8069d3
3 changed files with 22 additions and 0 deletions
|
|
@ -7661,6 +7661,11 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
|
|||
if (p_function->arguments_usage[i] == 0 && !p_function->arguments[i].operator String().begins_with("_")) {
|
||||
_add_warning(GDScriptWarning::UNUSED_ARGUMENT, p_function->line, p_function->name, p_function->arguments[i].operator String());
|
||||
}
|
||||
for (int j = 0; j < current_class->variables.size(); j++) {
|
||||
if (current_class->variables[j].identifier == p_function->arguments[i]) {
|
||||
_add_warning(GDScriptWarning::SHADOWED_VARIABLE, p_function->line, p_function->arguments[i], itos(current_class->variables[j].line));
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
|
|
@ -7734,6 +7739,17 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
|
|||
p_function->return_type.has_type = false;
|
||||
p_function->return_type.may_yield = true;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
for (Map<StringName, LocalVarNode *>::Element *E = p_function->body->variables.front(); E; E = E->next()) {
|
||||
LocalVarNode *lv = E->get();
|
||||
for (int i = 0; i < current_class->variables.size(); i++) {
|
||||
if (current_class->variables[i].identifier == lv->name) {
|
||||
_add_warning(GDScriptWarning::SHADOWED_VARIABLE, lv->line, lv->name, itos(current_class->variables[i].line));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue