1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed null coalescing for function pointers

This commit is contained in:
Brian Fiete 2021-02-14 06:40:02 -08:00
parent 6e58454825
commit ed679f6f10

View file

@ -20615,14 +20615,19 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
return;
}
if ((binaryOp == BfBinaryOp_NullCoalesce) && ((leftValue.mType->IsPointer()) || (leftValue.mType->IsObject())))
if ((binaryOp == BfBinaryOp_NullCoalesce) && ((leftValue.mType->IsPointer()) || (leftValue.mType->IsFunction()) || (leftValue.mType->IsObject())))
{
auto prevBB = mModule->mBfIRBuilder->GetInsertBlock();
auto rhsBB = mModule->mBfIRBuilder->CreateBlock("nullc.rhs");
auto endBB = mModule->mBfIRBuilder->CreateBlock("nullc.end");
auto isNull = mModule->mBfIRBuilder->CreateIsNull(leftValue.mValue);
BfIRValue isNull;
if (leftValue.mType->IsFunction())
isNull = mModule->mBfIRBuilder->CreateIsNull(
mModule->mBfIRBuilder->CreateIntToPtr(leftValue.mValue, mModule->mBfIRBuilder->MapType(mModule->GetPrimitiveType(BfTypeCode_NullPtr))));
else
isNull = mModule->mBfIRBuilder->CreateIsNull(leftValue.mValue);
mModule->mBfIRBuilder->CreateCondBr(isNull, rhsBB, endBB);
mModule->AddBasicBlock(rhsBB);