Skip to content

Commit 7459a03

Browse files
committedMar 7, 2025··
Merge pull request #103177 from Murrent/shader_default_at_top
Allow `default` case at the top of a switch scope in shaders
2 parents 67d4a24 + 4f46ecc commit 7459a03

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎servers/rendering/shader_language.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -8460,9 +8460,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
84608460

84618461
pos = _get_tkpos();
84628462
tk = _get_token();
8463-
TokenType prev_type;
8463+
bool has_default = false;
84648464
if (tk.type == TK_CF_CASE || tk.type == TK_CF_DEFAULT) {
8465-
prev_type = tk.type;
8465+
if (tk.type == TK_CF_DEFAULT) {
8466+
has_default = true;
8467+
}
84668468
_set_tkpos(pos);
84678469
} else {
84688470
_set_expected_error("case", "default");
@@ -8476,17 +8478,15 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
84768478
}
84778479
pos = _get_tkpos();
84788480
tk = _get_token();
8479-
if (tk.type == TK_CF_CASE || tk.type == TK_CF_DEFAULT) {
8480-
if (prev_type == TK_CF_DEFAULT) {
8481-
if (tk.type == TK_CF_CASE) {
8482-
_set_error(RTR("Cases must be defined before default case."));
8483-
return ERR_PARSE_ERROR;
8484-
} else if (prev_type == TK_CF_DEFAULT) {
8485-
_set_error(RTR("Default case must be defined only once."));
8486-
return ERR_PARSE_ERROR;
8487-
}
8481+
if (tk.type == TK_CF_CASE) {
8482+
_set_tkpos(pos);
8483+
continue;
8484+
} else if (tk.type == TK_CF_DEFAULT) {
8485+
if (has_default) {
8486+
_set_error(RTR("Default case must be defined only once."));
8487+
return ERR_PARSE_ERROR;
84888488
}
8489-
prev_type = tk.type;
8489+
has_default = true;
84908490
_set_tkpos(pos);
84918491
continue;
84928492
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.