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

Fixed enum underlying resolution with extension, ToString of void enum

This commit is contained in:
Brian Fiete 2024-11-20 10:31:53 -05:00
parent 28783a6b5a
commit 237b507745
2 changed files with 35 additions and 22 deletions

View file

@ -18839,7 +18839,9 @@ void BfModule::EmitEnumToStringBody()
paramTypes.Add(stringType);
auto appendModuleMethodInstance = GetMethodByName(stringType->ToTypeInstance(), "Append", paramTypes);
auto switchVal = mBfIRBuilder->CreateSwitch(enumVal, noMatchBlock, (int)mCurTypeInstance->mFieldInstances.size());
BfIRValue switchVal;
if (!mCurTypeInstance->IsValuelessType())
switchVal = mBfIRBuilder->CreateSwitch(enumVal, noMatchBlock, (int)mCurTypeInstance->mFieldInstances.size());
HashSet<int64> handledCases;
for (auto& fieldInstance : mCurTypeInstance->mFieldInstances)
@ -18847,10 +18849,10 @@ void BfModule::EmitEnumToStringBody()
if (fieldInstance.mIsEnumPayloadCase)
{
int tagId = -fieldInstance.mDataIdx - 1;
BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case");
mBfIRBuilder->AddBlock(caseBlock);
mBfIRBuilder->SetInsertPoint(caseBlock);
BF_ASSERT(discriminatorType->IsPrimitiveType());
auto constVal = mBfIRBuilder->CreateConst(((BfPrimitiveType*)discriminatorType)->mTypeDef->mTypeCode, tagId);
mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock);
@ -18903,12 +18905,15 @@ void BfModule::EmitEnumToStringBody()
continue;
}
if (switchVal)
{
BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case");
mBfIRBuilder->AddBlock(caseBlock);
mBfIRBuilder->SetInsertPoint(caseBlock);
BfIRValue constVal = ConstantToCurrent(constant, mCurTypeInstance->mConstHolder, mCurTypeInstance);
mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock);
}
auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName);
mBfIRBuilder->CreateStore(caseStr, strVal);
@ -18923,6 +18928,9 @@ void BfModule::EmitEnumToStringBody()
args.Add(stringDestVal.mValue);
args.Add(mBfIRBuilder->CreateLoad(strVal));
exprEvaluator.CreateCall(NULL, appendModuleMethodInstance.mMethodInstance, appendModuleMethodInstance.mFunc, false, args);
if (switchVal)
{
mBfIRBuilder->CreateBr(endBlock);
mBfIRBuilder->AddBlock(noMatchBlock);
@ -18939,6 +18947,7 @@ void BfModule::EmitEnumToStringBody()
mBfIRBuilder->AddBlock(endBlock);
mBfIRBuilder->SetInsertPoint(endBlock);
}
}
void BfModule::EmitTupleToStringBody()
{

View file

@ -3955,6 +3955,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
for (auto baseTypeRef : typeDef->mBaseTypes)
{
auto declTypeDef = typeDef;
if (typeDef->mIsCombinedPartial)
declTypeDef = typeDef->mPartials.front();
SetAndRestoreValue<BfTypeDef*> prevTypeDef(mContext->mCurTypeState->mCurTypeDef, declTypeDef);
SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, baseTypeRef);
SetAndRestoreValue<BfTypeDefineState> prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType);
SetAndRestoreValue<bool> prevIgnoreError(mIgnoreErrors, true);