Fix shader crash when the comma used in `for` loop as a trailing

This commit is contained in:
Chaosus 2024-08-10 11:07:53 +03:00
parent c73ac74c4a
commit d74749fd60
2 changed files with 18 additions and 0 deletions

View File

@ -898,6 +898,13 @@ bool ShaderLanguage::_lookup_next(Token &r_tk) {
return false;
}
ShaderLanguage::Token ShaderLanguage::_peek() {
TkPos pre_pos = _get_tkpos();
Token tk = _get_token();
_set_tkpos(pre_pos);
return tk;
}
String ShaderLanguage::token_debug(const String &p_code) {
clear();
@ -8080,6 +8087,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
_set_error(RTR("The middle expression is expected to be a boolean operator."));
return ERR_PARSE_ERROR;
}
tk = _peek();
if (tk.type == TK_SEMICOLON) {
_set_error(vformat(RTR("Expected expression, found: '%s'."), get_token_text(tk)));
return ERR_PARSE_ERROR;
}
continue;
}
if (tk.type != TK_SEMICOLON) {
@ -8088,6 +8100,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
}
} else if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_EXPRESSION) {
if (tk.type == TK_COMMA) {
tk = _peek();
if (tk.type == TK_PARENTHESIS_CLOSE) {
_set_error(vformat(RTR("Expected expression, found: '%s'."), get_token_text(tk)));
return ERR_PARSE_ERROR;
}
continue;
}
if (tk.type != TK_PARENTHESIS_CLOSE) {

View File

@ -1037,6 +1037,7 @@ private:
Token _make_token(TokenType p_type, const StringName &p_text = StringName());
Token _get_token();
bool _lookup_next(Token &r_tk);
Token _peek();
ShaderNode *shader = nullptr;