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

Fixed conditional var initializer with valueless nullable

This commit is contained in:
Brian Fiete 2025-03-07 12:37:40 -08:00
parent d778187e34
commit 805d312c98
2 changed files with 14 additions and 2 deletions

View file

@ -1585,11 +1585,15 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
{
if (initValue.mType->IsNullable())
{
auto nullableElementType = initValue.mType->GetUnderlyingType();
auto boolType = GetPrimitiveType(BfTypeCode_Boolean);
initValue = LoadValue(initValue);
exprEvaluator->mResult = BfTypedValue(mBfIRBuilder->CreateExtractValue(initValue.mValue, 2), boolType);
exprEvaluator->mResult = BfTypedValue(mBfIRBuilder->CreateExtractValue(initValue.mValue, nullableElementType->IsValuelessType() ? 1 : 2), boolType);
handledExprBoolResult = true;
initValue = BfTypedValue(mBfIRBuilder->CreateExtractValue(initValue.mValue, 1), initValue.mType->GetUnderlyingType());
if (!nullableElementType->IsValuelessType())
initValue = BfTypedValue(mBfIRBuilder->CreateExtractValue(initValue.mValue, 1), initValue.mType->GetUnderlyingType());
else
initValue = BfTypedValue(mBfIRBuilder->GetFakeVal(), nullableElementType);
}
else
{