From 837cba7567d7ddfeddba35d6590108624399d9d2 Mon Sep 17 00:00:00 2001 From: Thakee Nathees Date: Thu, 4 Jun 2020 10:37:22 +0530 Subject: [PATCH] predefined var check for `for` loop counter (cherry picked from commit e153772de2a52795aefb2f0c11c69396d04c61d5) --- modules/gdscript/gdscript_parser.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 2c9c62edc0a..5606c01dd5c 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -3121,6 +3121,15 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { IdentifierNode *id = alloc_node(); id->name = tokenizer->get_token_identifier(); + BlockNode *check_block = p_block; + while (check_block) { + if (check_block->variables.has(id->name)) { + _set_error("Variable \"" + String(id->name) + "\" already defined in the scope (at line " + itos(check_block->variables[id->name]->line) + ")."); + return; + } + check_block = check_block->parent_block; + } + tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_OP_IN) {