mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Fixed premature enum finalization during cast
This commit is contained in:
parent
ef942366db
commit
95c6b1db98
2 changed files with 16 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
@ -122,7 +133,10 @@ namespace Tests
|
|||
}
|
||||
|
||||
ee = .B(10);
|
||||
|
||||
|
||||
EnumG eg = .A;
|
||||
eg.Set(66);
|
||||
Test.Assert(eg == .B);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue