1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Implement pattern guards for match statement

Within a match statement, it is now possible to add guards in each
branch:

	var a = 0
	match a:
		0 when false: print("does not run")
		0 when true: print("but this does")

This allows more complex logic for deciding which branch to take.
This commit is contained in:
George Marques
2023-07-31 07:47:26 -03:00
parent ec62b8a3ee
commit 54a1414500
15 changed files with 163 additions and 1 deletions

View File

@@ -2219,6 +2219,10 @@ void GDScriptAnalyzer::resolve_match_branch(GDScriptParser::MatchBranchNode *p_m
resolve_match_pattern(p_match_branch->patterns[i], p_match_test);
}
if (p_match_branch->guard_body) {
resolve_suite(p_match_branch->guard_body);
}
resolve_suite(p_match_branch->block);
decide_suite_type(p_match_branch, p_match_branch->block);