-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72285 from vnen/gdscript-variable-match
GDScript: Allow variables in match patterns
- Loading branch information
Showing
8 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
func test(): | ||
var dict = { a = 1 } | ||
match 2: | ||
dict["a"]: | ||
print("not allowed") |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Expression in match pattern must be a constant expression, an identifier, or an attribute access ("A.B"). |
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
func test(): | ||
var a = 1 | ||
match 2: | ||
a + 2: | ||
print("not allowed") |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Expression in match pattern must be a constant expression, an identifier, or an attribute access ("A.B"). |
22 changes: 22 additions & 0 deletions
22
modules/gdscript/tests/scripts/parser/features/match_with_variables.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
func test(): | ||
var a = 1 | ||
match 1: | ||
a: | ||
print("reach 1") | ||
|
||
var dict = { b = 2 } | ||
match 2: | ||
dict.b: | ||
print("reach 2") | ||
|
||
var nested_dict = { | ||
sub = { c = 3 } | ||
} | ||
match 3: | ||
nested_dict.sub.c: | ||
print("reach 3") | ||
|
||
var sub_pattern = { d = 4 } | ||
match [4]: | ||
[sub_pattern.d]: | ||
print("reach 4") |
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/parser/features/match_with_variables.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GDTEST_OK | ||
reach 1 | ||
reach 2 | ||
reach 3 | ||
reach 4 |