Merge pull request #62701 from cdemirer/for-variable-conflict

This commit is contained in:
Rémi Verschelde 2022-07-06 16:02:49 +02:00 committed by GitHub
commit f0eb3ac5d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 0 deletions

View file

@ -1777,6 +1777,10 @@ GDScriptParser::ForNode *GDScriptParser::parse_for() {
SuiteNode *suite = alloc_node<SuiteNode>();
if (n_for->variable) {
const SuiteNode::Local &local = current_suite->get_local(n_for->variable->name);
if (local.type != SuiteNode::Local::UNDEFINED) {
push_error(vformat(R"(There is already a %s named "%s" declared in this scope.)", local.get_name(), n_for->variable->name), n_for->variable);
}
suite->add_local(SuiteNode::Local(n_for->variable, current_function));
}
suite->parent_for = n_for;

View file

@ -0,0 +1,4 @@
func test():
var TEST = 1
for TEST in 2:
pass

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a variable named "TEST" declared in this scope.

View file

@ -0,0 +1,3 @@
func test():
var TEST = 1
var TEST = 2

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a variable named "TEST" declared in this scope.