Merge pull request #57694 from Chaosus/shader_fix-for_loop

Fix unknown identifier error in for loop
This commit is contained in:
Rémi Verschelde 2022-02-06 11:18:20 +01:00 committed by GitHub
commit fd0d2dcabf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 11 deletions

View File

@ -6495,9 +6495,17 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
decl.name = name; decl.name = name;
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (check_warnings && HAS_WARNING(ShaderWarning::UNUSED_LOCAL_VARIABLE_FLAG)) { if (check_warnings && HAS_WARNING(ShaderWarning::UNUSED_LOCAL_VARIABLE_FLAG) && p_block) {
if (p_block && p_block->parent_function) { FunctionNode *parent_function = nullptr;
StringName func_name = p_block->parent_function->name; {
BlockNode *block = p_block;
while (block && !block->parent_function) {
block = block->parent_block;
}
parent_function = block->parent_function;
}
if (parent_function) {
StringName func_name = parent_function->name;
if (!used_local_vars.has(func_name)) { if (!used_local_vars.has(func_name)) {
used_local_vars.insert(func_name, Map<StringName, Usage>()); used_local_vars.insert(func_name, Map<StringName, Usage>());
@ -7141,14 +7149,6 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
init_block->block_type = BlockNode::BLOCK_TYPE_FOR_INIT; init_block->block_type = BlockNode::BLOCK_TYPE_FOR_INIT;
init_block->parent_block = p_block; init_block->parent_block = p_block;
init_block->single_statement = true; init_block->single_statement = true;
// Need to find a parent function to correctly proceed unused variable warnings.
{
BlockNode *block = p_block;
while (block && !block->parent_function) {
block = block->parent_block;
}
init_block->parent_function = block->parent_function;
}
cf->blocks.push_back(init_block); cf->blocks.push_back(init_block);
Error err = _parse_block(init_block, p_function_info, true, false, false); Error err = _parse_block(init_block, p_function_info, true, false, false);
if (err != OK) { if (err != OK) {