diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 255b0f86..c20dfb82 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -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