1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fixed crashes related to attempts at comptime delegate binding

This commit is contained in:
Brian Fiete 2021-08-02 12:30:05 -07:00
parent 16829900bc
commit 974b3a58e8
2 changed files with 24 additions and 13 deletions

View file

@ -12069,6 +12069,9 @@ void BfExprEvaluator::VisitLambdaBodies(BfAstNode* body, BfFieldDtorDeclaration*
BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lambdaBindExpr, BfAllocTarget& allocTarget)
{
if (mModule->mCurMethodState == NULL)
return NULL;
auto rootMethodState = mModule->mCurMethodState->GetRootMethodState();
BfAstNodeList cacheNodeList;
cacheNodeList.mList.Add(lambdaBindExpr);
@ -12301,6 +12304,8 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
Val128 val128(delegateTypeInstance->mTypeId);
bool isConstEval = ((mBfEvalExprFlags & BfEvalExprFlags_Comptime) != 0);
BfMethodState methodState;
methodState.mPrevMethodState = mModule->mCurMethodState;
BfIRFunctionType funcType;
@ -12309,7 +12314,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
funcType = mModule->mBfIRBuilder->CreateFunctionType(mModule->mBfIRBuilder->MapType(voidType), paramTypes, false);
auto prevInsertBlock = mModule->mBfIRBuilder->GetInsertBlock();
BF_ASSERT(prevInsertBlock);
BF_ASSERT(prevInsertBlock || isConstEval);
auto prevActiveFunction = mModule->mBfIRBuilder->GetActiveFunction();
mModule->mBfIRBuilder->SaveDebugLocation();
@ -12887,7 +12892,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
prevMethodState.Restore();
mModule->mBfIRBuilder->SetActiveFunction(prevActiveFunction);
if (!prevInsertBlock.IsFake())
if ((prevInsertBlock) && (!prevInsertBlock.IsFake()))
mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock);
// Just a check
@ -13069,7 +13074,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
}
prevClosureState.Restore();
if (!prevInsertBlock.IsFake())
if ((prevInsertBlock) && (!prevInsertBlock.IsFake()))
mModule->mBfIRBuilder->SetInsertPoint(prevInsertBlock);
for (auto& capturedEntry : capturedEntries)