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

Fixed premature enum finalization during cast

This commit is contained in:
Brian Fiete 2022-02-12 14:21:52 -05:00
parent ef942366db
commit 95c6b1db98
2 changed files with 16 additions and 4 deletions

View file

@ -13328,8 +13328,6 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf
if (typedVal.mType == toType)
return typedVal;
PopulateType(toType, ((castFlags & BfCastFlags_NoConversionOperator) != 0) ? BfPopulateType_Data : BfPopulateType_DataAndMethods);
if ((toType->IsSizedArray()) && (typedVal.mType->IsSizedArray()))
{
// Retain our type if we're casting from a known-sized array to an unknown-sized arrays
@ -13341,6 +13339,7 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf
if ((castFlags & BfCastFlags_Force) != 0)
{
PopulateType(toType, BfPopulateType_Data);
if (toType->IsValuelessType())
return BfTypedValue(mBfIRBuilder->GetFakeVal(), toType);
@ -13365,7 +13364,6 @@ BfTypedValue BfModule::Cast(BfAstNode* srcNode, const BfTypedValue& typedVal, Bf
// This tuple cast may create a new type if the toType contains 'var' entries
if ((typedVal.mType->IsTuple()) && (toType->IsTuple()))
{
//auto loadedVal = LoadValue(typedVal);
PopulateType(toType);
auto fromTupleType = (BfTypeInstance*)typedVal.mType;

View file

@ -43,6 +43,17 @@ namespace Tests
case EE(EnumE ee);
}
enum EnumG
{
case A = (.)'A';
case B = (.)'B';
public void Set(int val) mut
{
this = (.)val;
}
}
[Test]
static void TestBasic()
{
@ -123,6 +134,9 @@ namespace Tests
ee = .B(10);
EnumG eg = .A;
eg.Set(66);
Test.Assert(eg == .B);
}
}
}