From c68b2358d58c9acd09dc9618bb7ba89246d759f7 Mon Sep 17 00:00:00 2001 From: George Marques Date: Sat, 28 Jan 2023 19:49:14 -0300 Subject: GDScript: Allow variables in match patterns To restore an ability available in 3.x and reduce compatibility changes. --- .../parser/features/match_with_variables.gd | 22 ++++++++++++++++++++++ .../parser/features/match_with_variables.out | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 modules/gdscript/tests/scripts/parser/features/match_with_variables.gd create mode 100644 modules/gdscript/tests/scripts/parser/features/match_with_variables.out (limited to 'modules/gdscript/tests/scripts/parser') diff --git a/modules/gdscript/tests/scripts/parser/features/match_with_variables.gd b/modules/gdscript/tests/scripts/parser/features/match_with_variables.gd new file mode 100644 index 0000000000..aa38c3bf41 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_with_variables.gd @@ -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") diff --git a/modules/gdscript/tests/scripts/parser/features/match_with_variables.out b/modules/gdscript/tests/scripts/parser/features/match_with_variables.out new file mode 100644 index 0000000000..de1dcb0d40 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_with_variables.out @@ -0,0 +1,5 @@ +GDTEST_OK +reach 1 +reach 2 +reach 3 +reach 4 -- cgit v1.2.3