1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 23:34:10 +02:00

Fixed enum issues utilizing Underlying in initializer

This commit is contained in:
Brian Fiete 2025-02-15 10:12:27 -08:00
parent f7b3f88868
commit fa251b3439
3 changed files with 28 additions and 2 deletions

View file

@ -22357,7 +22357,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
BfIRValue fromBool; BfIRValue fromBool;
mBfIRBuilder->RestoreDebugLocation(); mBfIRBuilder->RestoreDebugLocation();
if (!mCompiler->mIsResolveOnly) if ((!mCompiler->mIsResolveOnly) || (mIsComptimeModule))
{ {
if (!mCurTypeInstance->IsValuelessType()) if (!mCurTypeInstance->IsValuelessType())
ret = mBfIRBuilder->CreateRet(GetThis().mValue); ret = mBfIRBuilder->CreateRet(GetThis().mValue);

View file

@ -3591,6 +3591,12 @@ void BfModule::DoPopulateType_InitSearches(BfTypeInstance* typeInstance)
void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType) void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred, HashContext* dataMemberHashCtx, BfType* unionInnerType)
{ {
if (typeInstance->mDefineState >= BfTypeDefineState_DefinedAndMethodsSlotting)
{
// Already locked
return;
}
if (typeInstance->IsEnum()) if (typeInstance->IsEnum())
{ {
int64 min = 0; int64 min = 0;

View file

@ -88,6 +88,20 @@ namespace Tests
// Started from 129 elements, no less // Started from 129 elements, no less
} }
[AllowDuplicates]
public enum EnumJ : uint32
{
SDL_BUTTON_LEFT = 1,
SDL_BUTTON_LMASK = (1u << ((SDL_BUTTON_LEFT.Underlying) - 1)),
}
[AllowDuplicates]
public enum EnumK
{
SDL_BUTTON_LEFT = 1,
SDL_BUTTON_LMASK = (1u << ((SDL_BUTTON_LEFT.Underlying) - 1)),
}
[Test] [Test]
static void TestBasic() static void TestBasic()
{ {
@ -229,6 +243,12 @@ namespace Tests
if (ei case .DY(var eh)) if (ei case .DY(var eh))
foundH = eh == .B; foundH = eh == .B;
Test.Assert(foundH); Test.Assert(foundH);
Test.Assert((int)EnumJ.SDL_BUTTON_LMASK == 1);
Test.Assert(typeof(EnumJ).Size == 4);
Test.Assert((int)EnumK.SDL_BUTTON_LMASK == 1);
Test.Assert(typeof(EnumK).Size == 8);
} }
} }
} }