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. --- .../gdscript/tests/scripts/analyzer/errors/match_with_subscript.gd | 5 +++++ .../gdscript/tests/scripts/analyzer/errors/match_with_subscript.out | 2 ++ .../tests/scripts/analyzer/errors/match_with_variable_expression.gd | 5 +++++ .../tests/scripts/analyzer/errors/match_with_variable_expression.out | 2 ++ 4 files changed, 14 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.out create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.out (limited to 'modules/gdscript/tests/scripts/analyzer') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.gd b/modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.gd new file mode 100644 index 0000000000..6d92db34c1 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.gd @@ -0,0 +1,5 @@ +func test(): + var dict = { a = 1 } + match 2: + dict["a"]: + print("not allowed") diff --git a/modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.out b/modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.out new file mode 100644 index 0000000000..b7385a50d5 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/match_with_subscript.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Expression in match pattern must be a constant expression, an identifier, or an attribute access ("A.B"). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.gd b/modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.gd new file mode 100644 index 0000000000..4df44d9ea2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.gd @@ -0,0 +1,5 @@ +func test(): + var a = 1 + match 2: + a + 2: + print("not allowed") diff --git a/modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.out b/modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.out new file mode 100644 index 0000000000..b7385a50d5 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/match_with_variable_expression.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Expression in match pattern must be a constant expression, an identifier, or an attribute access ("A.B"). -- cgit v1.2.3