From 931a927a40c7152fc6e47b99f99480e9ac273901 Mon Sep 17 00:00:00 2001 From: Thakee Nathees Date: Thu, 4 Jun 2020 10:28:09 +0530 Subject: [PATCH] shodowed var warning for `for` loop counter Fix: #39268 (cherry picked from commit 54835a530210c9620973a63dd30ff1d6bbe43a96) --- modules/gdscript/gdscript_parser.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 0b9ce345970..bef6d2c0eee 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3120,6 +3120,13 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { IdentifierNode *id = alloc_node(); id->name = tokenizer->get_token_identifier(); +#ifdef DEBUG_ENABLED + for (int j = 0; j < current_class->variables.size(); j++) { + if (current_class->variables[j].identifier == id->name) { + _add_warning(GDScriptWarning::SHADOWED_VARIABLE, id->line, id->name, itos(current_class->variables[j].line)); + } + } +#endif // DEBUG_ENABLED BlockNode *check_block = p_block; while (check_block) {