1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fixed reflection of generic attributes

This commit is contained in:
Brian Fiete 2022-03-03 12:55:56 -08:00
parent b1a772e652
commit b364760105
2 changed files with 69 additions and 0 deletions

View file

@ -5564,6 +5564,9 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
}
}
if (TypeIsSubTypeOf(typeInstance, mCompiler->mAttributeTypeDef))
wantsOnDemandMethods = false;
//bool allDeclsRequired = (mIsReified) && (mCompiler->mOptions.mEmitDebugInfo) && ();
bool allDeclsRequired = false;
//if ((mIsReified) && (mCompiler->mOptions.mEmitDebugInfo) && (!mCompiler->mWantsDeferMethodDecls))
@ -13979,6 +13982,71 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType
return TypeIsSubTypeOf(srcBaseType, wantType);
}
bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeDef* wantType)
{
if ((srcType == NULL) || (wantType == NULL))
return false;
if (srcType->IsInstanceOf(wantType))
return true;
if (srcType->mDefineState < BfTypeDefineState_HasInterfaces)
{
if (srcType->mDefineState == BfTypeDefineState_ResolvingBaseType)
{
auto typeState = mContext->mCurTypeState;
while (typeState != NULL)
{
if ((typeState->mType == srcType) && (typeState->mCurBaseType != NULL))
{
return TypeIsSubTypeOf(typeState->mCurBaseType, wantType);
}
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
PopulateType(srcType, BfPopulateType_Interfaces);
}
if (wantType->mTypeCode == BfTypeCode_Interface)
{
BfTypeDef* checkActiveTypeDef = NULL;
auto checkType = srcType;
while (checkType != NULL)
{
for (auto ifaceInst : checkType->mInterfaces)
{
if (ifaceInst.mInterfaceType->IsInstanceOf(wantType))
return true;
}
checkType = checkType->GetImplBaseType();
if ((checkType != NULL) && (checkType->mDefineState < BfTypeDefineState_HasInterfaces))
{
PopulateType(checkType, BfPopulateType_Interfaces);
}
}
if (srcType->IsTypedPrimitive())
{
BfType* underlyingType = srcType->GetUnderlyingType();
if (underlyingType->IsWrappableType())
{
BfTypeInstance* wrappedType = GetWrappedStructType(underlyingType);
if ((wrappedType != NULL) && (wrappedType != srcType))
return TypeIsSubTypeOf(wrappedType, wantType);
}
}
return false;
}
auto srcBaseType = srcType->mBaseType;
return TypeIsSubTypeOf(srcBaseType, wantType);
}
// Positive value means that toType encompasses fromType, negative value means toType is encompassed by formType
// INT_MAX means the types are not related
int BfModule::GetTypeDistance(BfType* fromType, BfType* toType)