mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #77744 from dalexeev/gds-reset-block-locals-on-exit
GDScript: Reset local variables on exit from block
This commit is contained in:
commit
faf3faa8c8
8 changed files with 96 additions and 14 deletions
|
@ -1536,6 +1536,11 @@ GDScriptParser::SuiteNode *GDScriptParser::parse_suite(const String &p_context,
|
|||
suite->parent_function = current_function;
|
||||
current_suite = suite;
|
||||
|
||||
if (!p_for_lambda && suite->parent_block != nullptr && suite->parent_block->is_in_loop) {
|
||||
// Do not reset to false if true is set before calling parse_suite().
|
||||
suite->is_in_loop = true;
|
||||
}
|
||||
|
||||
bool multiline = false;
|
||||
|
||||
if (match(GDScriptTokenizer::Token::NEWLINE)) {
|
||||
|
@ -1871,9 +1876,8 @@ GDScriptParser::ForNode *GDScriptParser::parse_for() {
|
|||
}
|
||||
suite->add_local(SuiteNode::Local(n_for->variable, current_function));
|
||||
}
|
||||
|
||||
suite->is_in_loop = true;
|
||||
n_for->loop = parse_suite(R"("for" block)", suite);
|
||||
n_for->loop->is_loop = true;
|
||||
complete_extents(n_for);
|
||||
|
||||
// Reset break/continue state.
|
||||
|
@ -2186,8 +2190,9 @@ GDScriptParser::WhileNode *GDScriptParser::parse_while() {
|
|||
can_break = true;
|
||||
can_continue = true;
|
||||
|
||||
n_while->loop = parse_suite(R"("while" block)");
|
||||
n_while->loop->is_loop = true;
|
||||
SuiteNode *suite = alloc_node<SuiteNode>();
|
||||
suite->is_in_loop = true;
|
||||
n_while->loop = parse_suite(R"("while" block)", suite);
|
||||
complete_extents(n_while);
|
||||
|
||||
// Reset break/continue state.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue