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

Allow boxed types to utilize comptime methods

This commit is contained in:
Brian Fiete 2021-12-16 07:28:03 -05:00
parent 8bc5d09787
commit 2932fceae4
7 changed files with 114 additions and 29 deletions

View file

@ -2747,7 +2747,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
resolvedTypeRef->mSize = typeInstance->mAlign = mSystem->mPtrSize;
}
BF_ASSERT((typeInstance->mMethodInstanceGroups.size() == 0) || (typeInstance->mMethodInstanceGroups.size() == typeDef->mMethods.size()) || (typeInstance->mCeTypeInfo != NULL));
BF_ASSERT((typeInstance->mMethodInstanceGroups.size() == 0) || (typeInstance->mMethodInstanceGroups.size() == typeDef->mMethods.size()) || (typeInstance->mCeTypeInfo != NULL) || (typeInstance->IsBoxed()));
typeInstance->mMethodInstanceGroups.Resize(typeDef->mMethods.size());
for (int i = 0; i < (int)typeInstance->mMethodInstanceGroups.size(); i++)
{
@ -3702,6 +3702,15 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (innerType->IsIncomplete())
PopulateType(innerType, BfPopulateType_Data);
auto innerTypeInst = innerType->ToTypeInstance();
if ((innerTypeInst != NULL) && (typeInstance->mTypeDef != innerTypeInst->mTypeDef))
{
// Rebuild with proper typedef (generally from inner type comptime emission)
typeInstance->mTypeDef = innerTypeInst->mTypeDef;
DoPopulateType(resolvedTypeRef, populateType);
return;
}
auto baseType = typeInstance->mBaseType;
dataPos = baseType->mInstSize;
int alignSize = BF_MAX(innerType->mAlign, baseType->mInstAlign);
@ -5666,15 +5675,15 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
}
else
{
auto matchedMethodDef = matchedMethod->mMethodDef;
if (matchedMethodDef->mDeclaringType->IsEmitted())
{
Fail("Boxed interface binding error to emitted method", mCurTypeInstance->mTypeDef->GetRefNode());
continue;
}
if (underlyingTypeInstance->mTypeDef->IsEmitted())
matchedMethodDef = underlyingTypeInstance->mTypeDef->mEmitParent->mMethods[matchedMethodDef->mIdx];
auto matchedMethodDef = matchedMethod->mMethodDef;
// if (matchedMethodDef->mDeclaringType->IsEmitted())
// {
// Fail("Boxed interface binding error to emitted method", mCurTypeInstance->mTypeDef->GetRefNode());
// continue;
// }
//
// if (underlyingTypeInstance->mTypeDef->IsEmitted())
// matchedMethodDef = underlyingTypeInstance->mTypeDef->mEmitParent->mMethods[matchedMethodDef->mIdx];
if (!matchedMethod->mIsForeignMethodDef)
{