summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorDaniel Spaniol <mail@daniel-spaniol.de>2019-02-20 20:49:48 +0100
committerDaniel Spaniol <mail@daniel-spaniol.de>2019-02-20 21:38:11 +0100
commit79176decd5dcbe7abc938458864f2191757b07dc (patch)
treea4bec80390611e483fc48048ff9a6c6b0826ba3d /modules
parent132e2f458df7a3551a251d68afeccd0362ca6be2 (diff)
downloadredot-engine-79176decd5dcbe7abc938458864f2191757b07dc.tar.gz
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.
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript_parser.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index b53d37226c..77055a5274 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -2211,6 +2211,8 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) {
void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &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())
@@ -2268,8 +2270,8 @@ void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBran
current_block = p_block;
- if (catch_all && branch->body->has_return) {
- p_block->has_return = true;
+ if (!branch->body->has_return) {
+ p_block->has_return = false;
}
p_branches.push_back(branch);