diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2019-04-16 09:25:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-16 09:25:36 +0200 |
| commit | cac650022f40efca0ba6aec946a583ef888ae25e (patch) | |
| tree | 0cf9434844bfcaf14d607bff799c5fb18c3bd544 /modules/gdscript/gdscript_parser.cpp | |
| parent | 0a40ac3246459c9d72ad217bd008ac3e900a6f15 (diff) | |
| parent | 14078fbb826811ca77e0eef3684f2e5d6f55a6b5 (diff) | |
| download | redot-engine-cac650022f40efca0ba6aec946a583ef888ae25e.tar.gz | |
Merge pull request #28053 from lupoDharkael/shadowing
GDScript: add variable shadowing warning
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
| -rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 8a9eacd835..80af094c2c 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -7658,6 +7658,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 } @@ -7731,6 +7736,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) { |
