summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-06-05 11:01:55 +0200
committerGitHub <noreply@github.com>2020-06-05 11:01:55 +0200
commit150ba031deefcde3fb84886d00666bd673fbedea (patch)
treed90a52ec3b6787cd13a6b57ec9376bb271020348 /modules
parentc0ff2a388dff38b86b888b9822f26cd3ab04e727 (diff)
parente153772de2a52795aefb2f0c11c69396d04c61d5 (diff)
Merge pull request #39276 from ThakeeNathees/predefined-check-for-loop-counter
Added predefined var check for `for` loop counter
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript_parser.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 0e498f6895..985ebbfdb5 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -3179,6 +3179,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) {