Skip to content

Commit edf29be

Browse files
committed
Bug fix with validation of function call returns.
1 parent 52abe54 commit edf29be

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

Compiler/src/SemanticValidator.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -663,29 +663,33 @@ void SemanticValidator::validate_value(std::shared_ptr<Branch> branch, struct se
663663
this->logger->error("Function: \"" + function_name + "\" returns type void this is illegal for expressions", func_call_branch);
664664
}
665665
}
666-
else if (s_info->sv_info.requires_pointer && (!func_def_return_type_branch->isPointer() || (return_data_type != s_info->sv_info.requirement_type && return_data_type != "void")))
667-
{
668-
this->logger->error("Function: \"" + function_name + "\" does not return a pointer of type \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
669-
}
670-
else if (!s_info->sv_info.requires_pointer && func_def_return_type_branch->isPointer())
671-
{
672-
this->logger->error("Function \"" + function_name + "\" returns a pointer of type \"" + s_info->sv_info.requirement_type + "\" but we are expecting a non pointer type of \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
673-
}
674-
else if (s_info->sv_info.requires_pointer && func_def_return_type_branch->isPointer() && s_info->sv_info.pointer_depth != func_def_return_type_branch->getPointerDepth())
675-
{
676-
this->logger->error("Function \"" + function_name + "\" returns a pointer of type \"" + s_info->sv_info.requirement_type + "\" with a pointer depth of " + std::to_string(func_def_return_type_branch->getPointerDepth()) + " but we are expecting a pointer depth of " + std::to_string(s_info->sv_info.pointer_depth), func_call_branch);
677-
}
678-
else if (getCompiler()->isPrimitiveDataType(s_info->sv_info.requirement_type) && !getCompiler()->isPrimitiveDataType(return_data_type))
679-
{
680-
this->logger->error("Function \"" + function_name + "\" is returning a non-primitive type of type: \"" + return_data_type + "\". Expecting a primitive type of type \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
681-
}
682-
else if (!getCompiler()->isPrimitiveDataType(s_info->sv_info.requirement_type) && getCompiler()->isPrimitiveDataType(return_data_type))
683-
{
684-
this->logger->error("Function \"" + function_name + "\" is returning a primitive type of type: \"" + return_data_type + "\". Expecting a non-primitive type of type \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
685-
}
686-
else if (return_data_type != "void" && getCompiler()->isPrimitiveDataType(s_info->sv_info.requirement_type) && !getCompiler()->canFit(s_info->sv_info.requirement_type, return_data_type))
666+
667+
if (s_info->sv_info.requirement_type != "")
687668
{
688-
this->logger->warn("Function: \"" + function_name + "\" returns type \"" + return_data_type + "\" but this primitive type cannot fit directly into \"" + s_info->sv_info.requirement_type + "\" data will be lost", func_call_branch);
669+
if (s_info->sv_info.requires_pointer && (!func_def_return_type_branch->isPointer() || (return_data_type != s_info->sv_info.requirement_type && return_data_type != "void")))
670+
{
671+
this->logger->error("Function: \"" + function_name + "\" does not return a pointer of type \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
672+
}
673+
else if (!s_info->sv_info.requires_pointer && func_def_return_type_branch->isPointer())
674+
{
675+
this->logger->error("Function \"" + function_name + "\" returns a pointer of type \"" + s_info->sv_info.requirement_type + "\" but we are expecting a non pointer type of \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
676+
}
677+
else if (s_info->sv_info.requires_pointer && func_def_return_type_branch->isPointer() && s_info->sv_info.pointer_depth != func_def_return_type_branch->getPointerDepth())
678+
{
679+
this->logger->error("Function \"" + function_name + "\" returns a pointer of type \"" + s_info->sv_info.requirement_type + "\" with a pointer depth of " + std::to_string(func_def_return_type_branch->getPointerDepth()) + " but we are expecting a pointer depth of " + std::to_string(s_info->sv_info.pointer_depth), func_call_branch);
680+
}
681+
else if (getCompiler()->isPrimitiveDataType(s_info->sv_info.requirement_type) && !getCompiler()->isPrimitiveDataType(return_data_type))
682+
{
683+
this->logger->error("Function \"" + function_name + "\" is returning a non-primitive type of type: \"" + return_data_type + "\". Expecting a primitive type of type \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
684+
}
685+
else if (!getCompiler()->isPrimitiveDataType(s_info->sv_info.requirement_type) && getCompiler()->isPrimitiveDataType(return_data_type))
686+
{
687+
this->logger->error("Function \"" + function_name + "\" is returning a primitive type of type: \"" + return_data_type + "\". Expecting a non-primitive type of type \"" + s_info->sv_info.requirement_type + "\"", func_call_branch);
688+
}
689+
else if (return_data_type != "void" && getCompiler()->isPrimitiveDataType(s_info->sv_info.requirement_type) && !getCompiler()->canFit(s_info->sv_info.requirement_type, return_data_type))
690+
{
691+
this->logger->warn("Function: \"" + function_name + "\" returns type \"" + return_data_type + "\" but this primitive type cannot fit directly into \"" + s_info->sv_info.requirement_type + "\" data will be lost", func_call_branch);
692+
}
689693
}
690694

691695

0 commit comments

Comments
 (0)