predefined var check for `for` loop counter

(cherry picked from commit e153772de2)
This commit is contained in:
Thakee Nathees 2020-06-04 10:37:22 +05:30 committed by Rémi Verschelde
parent 48a4f7e3a7
commit 837cba7567
1 changed files with 9 additions and 0 deletions

View File

@ -3121,6 +3121,15 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
IdentifierNode *id = alloc_node<IdentifierNode>();
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) {