GDScript: Implement pattern guards for match statement
Within a match statement, it is now possible to add guards in each
branch:
var a = 0
match a:
0 when false: print("does not run")
0 when true: print("but this does")
This allows more complex logic for deciding which branch to take.
This commit is contained in:
@ -0,0 +1,5 @@
|
||||
func test():
|
||||
var a = 0
|
||||
match a:
|
||||
0 when a = 1:
|
||||
print("assignment not allowed on pattern guard")
|
||||
@ -0,0 +1,2 @@
|
||||
GDTEST_PARSER_ERROR
|
||||
Assignment is not allowed inside an expression.
|
||||
@ -14,3 +14,7 @@ func test():
|
||||
|
||||
var TAU = "TAU"
|
||||
print(TAU)
|
||||
|
||||
# New keyword for pattern guards.
|
||||
var when = "when"
|
||||
print(when)
|
||||
|
||||
@ -4,3 +4,4 @@ PI
|
||||
INF
|
||||
NAN
|
||||
TAU
|
||||
when
|
||||
|
||||
Reference in New Issue
Block a user