Merge pull request #59863 from cdemirer/fix-match-multiple-bind-single-pattern
Fix issues with multiple bind patterns in match statement
This commit is contained in:
commit
9963ae3553
5 changed files with 18 additions and 1 deletions
|
|
@ -1863,7 +1863,7 @@ GDScriptParser::MatchBranchNode *GDScriptParser::parse_match_branch() {
|
||||||
if (pattern == nullptr) {
|
if (pattern == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (pattern->pattern_type == PatternNode::PT_BIND) {
|
if (pattern->binds.size() > 0) {
|
||||||
has_bind = true;
|
has_bind = true;
|
||||||
}
|
}
|
||||||
if (branch->patterns.size() > 0 && has_bind) {
|
if (branch->patterns.size() > 0 && has_bind) {
|
||||||
|
|
@ -1899,6 +1899,7 @@ GDScriptParser::MatchBranchNode *GDScriptParser::parse_match_branch() {
|
||||||
|
|
||||||
for (const StringName &E : binds) {
|
for (const StringName &E : binds) {
|
||||||
SuiteNode::Local local(branch->patterns[0]->binds[E], current_function);
|
SuiteNode::Local local(branch->patterns[0]->binds[E], current_function);
|
||||||
|
local.type = SuiteNode::Local::PATTERN_BIND;
|
||||||
suite->add_local(local);
|
suite->add_local(local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
func test():
|
||||||
|
match 1:
|
||||||
|
[[[var a]]], 2:
|
||||||
|
pass
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
GDTEST_PARSER_ERROR
|
||||||
|
Cannot use a variable bind with multiple patterns.
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
func test():
|
||||||
|
match [1, 2, 3]:
|
||||||
|
[var a, var b, var c]:
|
||||||
|
print(a == 1)
|
||||||
|
print(b == 2)
|
||||||
|
print(c == 3)
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
GDTEST_OK
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
Loading…
Add table
Add a link
Reference in a new issue