You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Do error when for variable conflicts with a variable in scope
This commit is contained in:
@@ -1748,6 +1748,10 @@ GDScriptParser::ForNode *GDScriptParser::parse_for() {
|
|||||||
|
|
||||||
SuiteNode *suite = alloc_node<SuiteNode>();
|
SuiteNode *suite = alloc_node<SuiteNode>();
|
||||||
if (n_for->variable) {
|
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->add_local(SuiteNode::Local(n_for->variable, current_function));
|
||||||
}
|
}
|
||||||
suite->parent_for = n_for;
|
suite->parent_for = n_for;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
func test():
|
||||||
|
var TEST = 1
|
||||||
|
for TEST in 2:
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GDTEST_PARSER_ERROR
|
||||||
|
There is already a variable named "TEST" declared in this scope.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
func test():
|
||||||
|
var TEST = 1
|
||||||
|
var TEST = 2
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GDTEST_PARSER_ERROR
|
||||||
|
There is already a variable named "TEST" declared in this scope.
|
||||||
Reference in New Issue
Block a user