diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index b6231d06b2b..21f7f293c3e 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2359,8 +2359,16 @@ GDScriptParser::MatchBranchNode *GDScriptParser::parse_match_branch() { } if (!consume(GDScriptTokenizer::Token::COLON, vformat(R"(Expected ":"%s after "match" %s.)", has_guard ? "" : R"( or "when")", has_guard ? "pattern guard" : "patterns"))) { + branch->block = alloc_recovery_suite(); complete_extents(branch); - return nullptr; + // Consume the whole line and treat the next one as new match branch. + while (current.type != GDScriptTokenizer::Token::NEWLINE && !is_at_end()) { + advance(); + } + if (!is_at_end()) { + advance(); + } + return branch; } SuiteNode *suite = alloc_node(); diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 47eab0c3420..2e0c3cbcddb 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1463,6 +1463,14 @@ private: return node; } + SuiteNode *alloc_recovery_suite() { + SuiteNode *suite = alloc_recovery_node(); + suite->parent_block = current_suite; + suite->parent_function = current_function; + suite->is_in_loop = current_suite->is_in_loop; + return suite; + } + void clear(); void push_error(const String &p_message, const Node *p_origin = nullptr); #ifdef DEBUG_ENABLED diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_1.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_1.cfg new file mode 100644 index 00000000000..8f42aad56f5 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_1.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "AUTO_TRANSLATE_MODE_INHERIT"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_1.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_1.gd new file mode 100644 index 00000000000..57aa7f4b020 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_1.gd @@ -0,0 +1,7 @@ +extends Node + +var t + +func test(): + match t: + AutoTranslateMode.➡ diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_2.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_2.cfg new file mode 100644 index 00000000000..50ef7900f52 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_2.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "VALUE"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_2.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_2.gd new file mode 100644 index 00000000000..bb54f146dce --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_2.gd @@ -0,0 +1,11 @@ +extends Node + +enum TestEnum { + VALUE, +} + +var t + +func test(): + match t: + TestEnum.➡ where diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_3.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_3.cfg new file mode 100644 index 00000000000..50ef7900f52 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_3.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "VALUE"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_3.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_3.gd new file mode 100644 index 00000000000..b7b24cad5ba --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_branch_3.gd @@ -0,0 +1,11 @@ +extends Node + +enum TestEnum { + VALUE, +} + +var t + +func test(): + match t: + TestEnum.➡: diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_1.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_1.cfg new file mode 100644 index 00000000000..8f42aad56f5 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_1.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "AUTO_TRANSLATE_MODE_INHERIT"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_1.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_1.gd new file mode 100644 index 00000000000..13dbafca1c5 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_1.gd @@ -0,0 +1,4 @@ +extends Node + +func test(): + match AutoTranslateMode.➡ diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_2.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_2.cfg new file mode 100644 index 00000000000..50ef7900f52 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_2.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "VALUE"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_2.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_2.gd new file mode 100644 index 00000000000..800cd389156 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_2.gd @@ -0,0 +1,8 @@ +extends Node + +enum TestEnum { + VALUE, +} + +func test(): + match TestEnum.➡: diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_3.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_3.cfg new file mode 100644 index 00000000000..8f42aad56f5 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_3.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "AUTO_TRANSLATE_MODE_INHERIT"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_3.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_3.gd new file mode 100644 index 00000000000..4659c4f38cd --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_3.gd @@ -0,0 +1,5 @@ +extends Node + +func test(): + match AutoTranslateMode.➡: + pass diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_4.cfg b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_4.cfg new file mode 100644 index 00000000000..50ef7900f52 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_4.cfg @@ -0,0 +1,4 @@ +[output] +include=[ + {"display": "VALUE"}, +] diff --git a/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_4.gd b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_4.gd new file mode 100644 index 00000000000..f5900fc0e7c --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/enum_values_in_match/in_test_4.gd @@ -0,0 +1,9 @@ +extends Node + +enum TestEnum { + VALUE, +} + +func test(): + match TestEnum.➡: + TestEnum