1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

WIP nullable fix

This commit is contained in:
Brian Fiete 2022-08-01 14:46:25 -04:00
parent 047ae9acc3
commit 0bedd77f0a

View file

@ -22925,10 +22925,19 @@ void BfExprEvaluator::PerformBinaryOperation(BfExpression* leftExpression, BfExp
bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken, BfExpression* leftExpression, BfExpression* rightExpression, BfTypedValue leftValue, BfType* wantType, BfTypedValue* assignTo)
{
if ((leftValue) && ((leftValue.mType->IsPointer()) || (leftValue.mType->IsFunction()) || (leftValue.mType->IsObject())))
if ((leftValue) && ((leftValue.mType->IsPointer()) || (leftValue.mType->IsFunction()) || (leftValue.mType->IsObject())) /* || (leftValue.mType->IsNullable())*/)
{
leftValue = mModule->LoadValue(leftValue);
BfIRValue nullableHasValue;
if (leftValue.mType->IsNullable())
{
if (wantType == leftValue.mType)
wantType = leftValue.mType->GetUnderlyingType();
nullableHasValue = mModule->mBfIRBuilder->CreateExtractValue(leftValue.mValue, 1);
leftValue = BfTypedValue(mModule->mBfIRBuilder->CreateExtractValue(leftValue.mValue, 0), leftValue.mType->GetUnderlyingType());
}
if (leftValue.mValue.IsConst())
{
auto constant = mModule->mBfIRBuilder->GetConstant(leftValue.mValue);
@ -22954,7 +22963,9 @@ bool BfExprEvaluator::PerformBinaryOperation_NullCoalesce(BfTokenNode* opToken,
auto endLhsBB = prevBB;
BfIRValue isNull;
if (leftValue.mType->IsFunction())
if (nullableHasValue)
isNull = mModule->mBfIRBuilder->CreateCmpEQ(nullableHasValue, mModule->mBfIRBuilder->CreateConst(BfTypeCode_Boolean, 0));
else if (leftValue.mType->IsFunction())
isNull = mModule->mBfIRBuilder->CreateIsNull(
mModule->mBfIRBuilder->CreateIntToPtr(leftValue.mValue, mModule->mBfIRBuilder->MapType(mModule->GetPrimitiveType(BfTypeCode_NullPtr))));
else