Skip to content

Commit

Permalink
feat: Added check for return type to match function type
Browse files Browse the repository at this point in the history
  • Loading branch information
alinalihassan committed May 28, 2022
1 parent 9510dbd commit 7c284ff
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/liblesma/Backend/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,20 @@ void Codegen::visit(Return *node) {
visit(inst);

isReturn = true;
if (node->getValue() == nullptr)
Builder->CreateRetVoid();
else
Builder->CreateRet(visit(node->getValue()));

if (node->getValue() == nullptr) {
if (Builder->getCurrentFunctionReturnType() == Builder->getVoidTy())
Builder->CreateRetVoid();
else
throw CodegenError(node->getSpan(), "Return type does not match the function return type");
}
else {
auto val = visit(node->getValue());
if (Builder->getCurrentFunctionReturnType() == val->getType())
Builder->CreateRet(val);
else
throw CodegenError(node->getSpan(), "Return type does not match the function return type");
}
}

void Codegen::visit(Defer *node) {
Expand Down

0 comments on commit 7c284ff

Please sign in to comment.