From 044ec35f62124aec602cfa62ad8296a47786f372 Mon Sep 17 00:00:00 2001 From: Daniel Spaniol Date: Wed, 20 Feb 2019 20:49:48 +0100 Subject: [PATCH] Require `return` in all match branches Before the parser only checked if the catch-all branch has a return in order to determine if the entire match block has a return. This code block was assumed to always return. match value: "test": print("test") _: return Now as soon as one of the branches has no return, the entire match block is marked to not have a return. (cherry picked from commit 79176decd5dcbe7abc938458864f2191757b07dc) --- modules/gdscript/gdscript_parser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index da69181a434..6b7379d350c 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2225,6 +2225,8 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector &p_branches, bool p_static) { int indent_level = tab_level.back()->get(); + p_block->has_return = true; + while (true) { while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) @@ -2282,8 +2284,8 @@ void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vectorbody->has_return) { - p_block->has_return = true; + if (!branch->body->has_return) { + p_block->has_return = false; } p_branches.push_back(branch);