1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Derived CRTP fixes

This commit is contained in:
Brian Fiete 2021-02-12 09:31:09 -08:00
parent fda6c326c0
commit a6e8436b2f
3 changed files with 45 additions and 1 deletions

View file

@ -143,10 +143,11 @@ public:
BfPopulateType mPopulateType;
BfTypeReference* mCurBaseTypeRef;
BfTypeInstance* mCurBaseType;
BfTypeReference* mCurAttributeTypeRef;
BfFieldDef* mCurFieldDef;
BfTypeDef* mCurTypeDef;
BfTypeDef* mForceActiveTypeDef;
BfTypeDef* mForceActiveTypeDef;
ResolveKind mResolveKind;
BfAstNode* mCurVarInitializer;
int mArrayInitializerSize;
@ -160,6 +161,7 @@ public:
mPopulateType = BfPopulateType_Identity;
mCurBaseTypeRef = NULL;
mCurBaseType = NULL;
mCurFieldDef = NULL;
mCurAttributeTypeRef = NULL;
mCurTypeDef = NULL;

View file

@ -3022,7 +3022,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
bool populateBase = !typeInstance->mTypeFailed;
auto checkType = ResolveTypeRef(checkTypeRef, BfPopulateType_Declaration);
if ((checkType != NULL) && (!checkType->IsInterface()) && (populateBase))
{
SetAndRestoreValue<BfTypeInstance*> prevBaseType(mContext->mCurTypeState->mCurBaseType, checkType->ToTypeInstance());
PopulateType(checkType, BfPopulateType_Data);
}
if (typeInstance->mDefineState >= BfTypeDefineState_Defined)
{
@ -12793,6 +12796,19 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType
if (srcType->mDefineState < BfTypeDefineState_HasInterfaces)
{
if (srcType->mDefineState == BfTypeDefineState_ResolvingBaseType)
{
auto typeState = mContext->mCurTypeState;
while (typeState != NULL)
{
if ((typeState->mTypeInstance == srcType) && (typeState->mCurBaseType != NULL))
{
return TypeIsSubTypeOf(typeState->mCurBaseType, wantType, checkAccessibility);
}
typeState = typeState->mPrevState;
}
}
// Type is incomplete. We don't do the IsIncomplete check here because of re-entry
// While handling 'var' resolution, we don't want to force a PopulateType reentry
// but we do have enough information for TypeIsSubTypeOf

View file

@ -0,0 +1,26 @@
namespace Tests
{
class Classes
{
public abstract class Plugin<T> where T : Plugin<T>, new, class
{
public abstract void OnLoad();
public abstract void OnUnload();
}
public abstract class ProgramPlugin<T> : Plugin<T> where T : ProgramPlugin<T>
{
}
public class ExamplePlugin : ProgramPlugin<ExamplePlugin>
{
public override void OnLoad()
{
}
public override void OnUnload()
{
}
}
}
}