1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Anonymous subclassing in initializer blocks

This commit is contained in:
Brian Fiete 2025-01-04 10:57:37 -08:00
parent 01c2c35fc3
commit a5e9a33f64
25 changed files with 1111 additions and 608 deletions

View file

@ -1508,7 +1508,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
mCurTypeDef->mProject = mCurSource->mProject;
mCurTypeDef->mNamespace = mNamespace;
mSystem->AddNamespaceUsage(mCurTypeDef->mNamespace, mCurTypeDef->mProject);
if (typeDeclaration->mTypeNode == NULL)
if ((typeDeclaration->mTypeNode == NULL) && (!isAnonymous))
{
mCurTypeDef->mIsPartial = true;
mCurTypeDef->mIsExplicitPartial = true;
@ -1750,7 +1750,11 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
if (typeDeclaration->mTypeNode != NULL)
typeToken = typeDeclaration->mTypeNode->GetToken();
if (typeDeclaration->mTypeNode == NULL)
if (typeDeclaration->IsAnonymousInitializerType())
{
mCurTypeDef->mTypeCode = BfTypeCode_Inferred;
}
else if (typeDeclaration->mTypeNode == NULL)
{
// Globals
mCurTypeDef->mTypeCode = BfTypeCode_Struct;
@ -1852,6 +1856,9 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
(checkTypeDef->mIsFunction == mCurTypeDef->mIsFunction) &&
(checkTypeDef->mOuterType == actualOuterTypeDef);
if ((mCurTypeDef->mTypeCode == BfTypeCode_Inferred) && (checkTypeDef->mTypeDeclaration->IsAnonymousInitializerType()))
isCompatible = true;
if (isCompatible)
{
if (prevRevisionTypeDef == NULL)
@ -1977,7 +1984,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
// Map methods into the correct index from previous revision
if (prevRevisionTypeDef != NULL)
{
BF_ASSERT(mCurTypeDef->mTypeCode == prevRevisionTypeDef->mTypeCode);
BF_ASSERT((mCurTypeDef->mTypeCode == prevRevisionTypeDef->mTypeCode) || (mCurTypeDef->mTypeCode == BfTypeCode_Inferred));
if (mCurTypeDef->mFullHash == prevRevisionTypeDef->mFullHash)
{
@ -2280,7 +2287,8 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
needsDynamicCastMethod = false;
}
if ((mCurTypeDef->mTypeCode == BfTypeCode_Object) && (!mCurTypeDef->mIsStatic) && (ctorClear == NULL))
if (((mCurTypeDef->mTypeCode == BfTypeCode_Object) || (mCurTypeDef->mTypeCode == BfTypeCode_Inferred)) &&
(!mCurTypeDef->mIsStatic) && (ctorClear == NULL))
{
auto methodDef = AddMethod(mCurTypeDef, BfMethodType_CtorClear, BfProtection_Private, false, "", mIsComptime);
methodDef->mIsMutating = true;
@ -2299,7 +2307,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
if ((needsStaticInit) && (staticCtor == NULL))
{
auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, BfProtection_Public, true, "", mIsComptime);
}
}
bool makeCtorPrivate = hasCtor;