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

Fixed dtor lookup

This commit is contained in:
Brian Fiete 2021-02-07 16:17:24 -08:00
parent eddbf7a984
commit 9268e3b25d
6 changed files with 73 additions and 37 deletions

View file

@ -830,7 +830,6 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild
{ {
BfTypeInstance* typeInst = type->ToTypeInstance(); BfTypeInstance* typeInst = type->ToTypeInstance();
if (type->IsDeleting()) if (type->IsDeleting())
{ {
return; return;
@ -2517,11 +2516,6 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS
BP_ZONE("BfContext::QueueMethodSpecializations"); BP_ZONE("BfContext::QueueMethodSpecializations");
if (typeInst->mTypeId == 578)
{
NOP;
}
auto module = typeInst->mModule; auto module = typeInst->mModule;
if (module == NULL) if (module == NULL)
return; return;

View file

@ -1916,13 +1916,7 @@ void BfModule::AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* r
bool hadDtorCall = false; bool hadDtorCall = false;
while (checkBaseType != NULL) while (checkBaseType != NULL)
{ {
checkBaseType->mTypeDef->PopulateMemberSets(); BfMethodDef* dtorMethodDef = checkBaseType->mTypeDef->GetMethodByName("~this");
BfMemberSetEntry* entry = NULL;
BfMethodDef* dtorMethodDef = NULL;
checkBaseType->mTypeDef->mMethodSet.TryGetWith(String("~this"), &entry);
if (entry != NULL)
dtorMethodDef = (BfMethodDef*)entry->mMemberDef;
if (dtorMethodDef != NULL) if (dtorMethodDef != NULL)
{ {
auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector()); auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector());
@ -15740,13 +15734,7 @@ void BfModule::EmitDtorBody()
UpdateSrcPos(typeDef->mTypeDeclaration->mNameNode); UpdateSrcPos(typeDef->mTypeDeclaration->mNameNode);
} }
checkBaseType->mTypeDef->PopulateMemberSets(); BfMethodDef* dtorMethodDef = checkBaseType->mTypeDef->GetMethodByName("~this");
BfMemberSetEntry* entry = NULL;
BfMethodDef* dtorMethodDef = NULL;
checkBaseType->mTypeDef->mMethodSet.TryGetWith(String("~this"), &entry);
if (entry != NULL)
dtorMethodDef = (BfMethodDef*)entry->mMemberDef;
if (dtorMethodDef != NULL) if (dtorMethodDef != NULL)
{ {
auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector()); auto dtorMethodInstance = GetMethodInstance(checkBaseType, dtorMethodDef, BfTypeVector());

View file

@ -2599,8 +2599,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance); SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance);
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, NULL); SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, NULL);
SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, NULL); SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, NULL);
SetAndRestoreValue<bool> prevHadError(mHadBuildError, false);
SetAndRestoreValue<bool> prevHadWarning(mHadBuildWarning, false); // WHY were we clearing these values?
//SetAndRestoreValue<bool> prevHadError(mHadBuildError, false);
//SetAndRestoreValue<bool> prevHadWarning(mHadBuildWarning, false);
BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState); BfTypeState typeState(mCurTypeInstance, mContext->mCurTypeState);
typeState.mPopulateType = populateType; typeState.mPopulateType = populateType;

View file

@ -3934,15 +3934,7 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt)
bool allowProtected = allowPrivate || TypeIsSubTypeOf(mCurTypeInstance, checkTypeInst); bool allowProtected = allowPrivate || TypeIsSubTypeOf(mCurTypeInstance, checkTypeInst);
while (checkTypeInst != NULL) while (checkTypeInst != NULL)
{ {
auto checkTypeDef = checkTypeInst->mTypeDef; auto dtorMethodDef = checkTypeInst->mTypeDef->GetMethodByName("~this");
checkTypeDef->PopulateMemberSets();
BfMemberSetEntry* entry = NULL;
BfMethodDef* dtorMethodDef = NULL;
checkTypeDef->mMethodSet.TryGetWith(String("~this"), &entry);
if (entry != NULL)
dtorMethodDef = (BfMethodDef*)entry->mMemberDef;
if (dtorMethodDef) if (dtorMethodDef)
{ {
if (!CheckProtection(dtorMethodDef->mProtection, checkTypeInst->mTypeDef, allowProtected, allowPrivate)) if (!CheckProtection(dtorMethodDef->mProtection, checkTypeInst->mTypeDef, allowProtected, allowPrivate))

View file

@ -833,12 +833,26 @@ int BfTypeDef::GetSelfGenericParamCount()
BfMethodDef* BfTypeDef::GetMethodByName(const StringImpl& name, int paramCount) BfMethodDef* BfTypeDef::GetMethodByName(const StringImpl& name, int paramCount)
{ {
for (auto method : mMethods) PopulateMemberSets();
{ BfMemberSetEntry* entry = NULL;
if ((name == method->mName) && ((paramCount == -1) || (paramCount == (int)method->mParams.size()))) if (!mMethodSet.TryGetWith(name, &entry))
return method;
}
return NULL; return NULL;
BfMethodDef* bestMethodDef = NULL;
auto methodDef = (BfMethodDef*)entry->mMemberDef;
while (methodDef != NULL)
{
if ((name == methodDef->mName) && ((paramCount == -1) || (paramCount == (int)methodDef->mParams.size())))
{
if ((bestMethodDef == NULL) ||
((bestMethodDef->mDeclaringType->IsExtension()) && (!methodDef->mDeclaringType->IsExtension())))
bestMethodDef = methodDef;
}
methodDef = methodDef->mNextWithSameName;
}
return bestMethodDef;
} }
BfFieldDef* BfTypeDef::GetFieldByName(const StringImpl& name) BfFieldDef* BfTypeDef::GetFieldByName(const StringImpl& name)

View file

@ -161,6 +161,32 @@ namespace Tests
} }
} }
class ClassF
{
public static int sVal = 3;
public int mF0 = 1 ~
{
sVal += 40;
};
}
extension ClassF
{
public int mF1 = 2 ~
{
sVal += 500;
};
}
class ClassG : ClassF
{
public int mG0 = 3 ~
{
sVal += 6000;
};
}
extension TClassA<T> where T : IGetExVal extension TClassA<T> where T : IGetExVal
{ {
public T mTVal; public T mTVal;
@ -226,6 +252,26 @@ namespace Tests
ClassE ce = scope .(); ClassE ce = scope .();
Test.Assert(ce.mD == 1); Test.Assert(ce.mD == 1);
Test.Assert(ce.mE == 1); Test.Assert(ce.mE == 1);
///
{
ClassF cf = scope .();
}
Test.Assert(ClassF.sVal == 543);
///
{
ClassF.sVal = 3;
ClassG cg = scope .();
}
Test.Assert(ClassF.sVal == 6543);
ClassF.sVal = 3;
Object obj = new ClassF();
delete obj;
Test.Assert(ClassF.sVal == 543);
ClassF.sVal = 3;
obj = new ClassG();
delete obj;
Test.Assert(ClassF.sVal == 6543);
} }
[Test] [Test]