GDScript: Allow variables in match patterns

To restore an ability available in 3.x and reduce compatibility changes.
This commit is contained in:
George Marques 2023-01-28 19:49:14 -03:00
parent 218bef90af
commit c68b2358d5
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
8 changed files with 59 additions and 15 deletions

View file

@ -1904,7 +1904,6 @@ GDScriptParser::MatchNode *GDScriptParser::parse_match() {
#ifdef DEBUG_ENABLED
bool all_have_return = true;
bool have_wildcard = false;
bool have_wildcard_without_continue = false;
#endif
while (!check(GDScriptTokenizer::Token::DEDENT) && !is_at_end()) {
@ -1915,19 +1914,12 @@ GDScriptParser::MatchNode *GDScriptParser::parse_match() {
}
#ifdef DEBUG_ENABLED
if (have_wildcard_without_continue && !branch->patterns.is_empty()) {
if (have_wildcard && !branch->patterns.is_empty()) {
push_warning(branch->patterns[0], GDScriptWarning::UNREACHABLE_PATTERN);
}
if (branch->has_wildcard) {
have_wildcard = true;
if (!branch->block->has_continue) {
have_wildcard_without_continue = true;
}
}
if (!branch->block->has_return) {
all_have_return = false;
}
have_wildcard = have_wildcard || branch->has_wildcard;
all_have_return = all_have_return && branch->block->has_return;
#endif
match->branches.push_back(branch);
}