Skip to content

Commit 4f46ecc

Browse files
committed
Allow default case at the top of a switch scope in shaders
Revert "Removed translations of unused error message" This reverts commit 6dbc75e. Variable name change Detecting multiple default cases in shaders Removed translations of unused error message Allowing default case at top of scope in switch statement in shaders
1 parent cc7a951 commit 4f46ecc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

servers/rendering/shader_language.cpp

Lines changed: 12 additions & 12 deletions
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)