From 54a1414500ee2f8f87647fc0ffe921498332446f Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 31 Jul 2023 07:47:26 -0300 Subject: 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. --- .../tests/scripts/analyzer/errors/match_guard_invalid_expression.gd | 4 ++++ .../tests/scripts/analyzer/errors/match_guard_invalid_expression.out | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.out (limited to 'modules/gdscript/tests/scripts/analyzer/errors') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.gd b/modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.gd new file mode 100644 index 0000000000..1dcb9fc36a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.gd @@ -0,0 +1,4 @@ +func test(): + match 0: + _ when a == 0: + print("a does not exist") diff --git a/modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.out b/modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.out new file mode 100644 index 0000000000..c5f0a90d6a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/match_guard_invalid_expression.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Identifier "a" not declared in the current scope. -- cgit v1.2.3