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

Improved handling of opaque types

This commit is contained in:
Brian Fiete 2025-01-14 11:45:44 -08:00
parent f96e231d7b
commit 16371ab07c
3 changed files with 37 additions and 26 deletions

View file

@ -1263,6 +1263,7 @@ BfFieldDef* BfDefBuilder::AddField(BfTypeDef* typeDef, BfTypeReference* fieldTyp
BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType, BfProtection protection, bool isStatic, const StringImpl& name, bool addedAfterEmit) BfMethodDef* BfDefBuilder::AddMethod(BfTypeDef* typeDef, BfMethodType methodType, BfProtection protection, bool isStatic, const StringImpl& name, bool addedAfterEmit)
{ {
BF_ASSERT(typeDef->mTypeCode != BfTypeCode_TypeAlias); BF_ASSERT(typeDef->mTypeCode != BfTypeCode_TypeAlias);
BF_ASSERT(!typeDef->mIsOpaque);
auto methodDef = new BfMethodDef(); auto methodDef = new BfMethodDef();
methodDef->mIdx = (int)typeDef->mMethods.size(); methodDef->mIdx = (int)typeDef->mMethods.size();
@ -2293,6 +2294,8 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
needsDynamicCastMethod = false; needsDynamicCastMethod = false;
} }
if (!mCurTypeDef->mIsOpaque)
{
if (((mCurTypeDef->mTypeCode == BfTypeCode_Object) || (mCurTypeDef->mTypeCode == BfTypeCode_Inferred)) && if (((mCurTypeDef->mTypeCode == BfTypeCode_Object) || (mCurTypeDef->mTypeCode == BfTypeCode_Inferred)) &&
(!mCurTypeDef->mIsStatic) && (ctorClear == NULL)) (!mCurTypeDef->mIsStatic) && (ctorClear == NULL))
{ {
@ -2314,6 +2317,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
{ {
auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, BfProtection_Public, true, "", mIsComptime); auto methodDef = AddMethod(mCurTypeDef, BfMethodType_Ctor, BfProtection_Public, true, "", mIsComptime);
} }
}
bool makeCtorPrivate = hasCtor; bool makeCtorPrivate = hasCtor;
@ -2322,7 +2326,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
if (mCurTypeDef->mTypeCode == BfTypeCode_Extension) if (mCurTypeDef->mTypeCode == BfTypeCode_Extension)
needsDefaultCtor = false; needsDefaultCtor = false;
if ((needsDefaultCtor) && ((!hasDefaultCtor))) if ((needsDefaultCtor) && (!hasDefaultCtor) && (!mCurTypeDef->mIsOpaque))
{ {
BfProtection prot = hasCtor ? BfProtection_Hidden : BfProtection_Public; BfProtection prot = hasCtor ? BfProtection_Hidden : BfProtection_Public;
if (mCurTypeDef->mName == mSystem->mEmptyAtom) if (mCurTypeDef->mName == mSystem->mEmptyAtom)
@ -2340,7 +2344,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
//TODO: Don't do this for the autocomplete pass //TODO: Don't do this for the autocomplete pass
if ((needsDynamicCastMethod) && (mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (mCurTypeDef->mTypeCode != BfTypeCode_Extension) && if ((needsDynamicCastMethod) && (mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (mCurTypeDef->mTypeCode != BfTypeCode_Extension) &&
(!mCurTypeDef->mIsStatic) && (!isAutocomplete) && (!isAlias)) (!mCurTypeDef->mIsStatic) && (!isAutocomplete) && (!isAlias) && (!mCurTypeDef->mIsOpaque))
{ {
AddDynamicCastMethods(mCurTypeDef); AddDynamicCastMethods(mCurTypeDef);
} }
@ -2361,7 +2365,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
if (isPayloadEnum) if (isPayloadEnum)
hasNonStaticField = true; hasNonStaticField = true;
if (mCurTypeDef->mTypeCode != BfTypeCode_Interface) if ((mCurTypeDef->mTypeCode != BfTypeCode_Interface) && (!mCurTypeDef->mIsOpaque))
{ {
if ((hasStaticField) && (staticMarkMethod == NULL)) if ((hasStaticField) && (staticMarkMethod == NULL))
{ {
@ -2389,7 +2393,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
if (toStringMethod != NULL) if (toStringMethod != NULL)
wantsToString = false; wantsToString = false;
if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL)) if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL) && (!mCurTypeDef->mIsOpaque))
{ {
auto methodDef = new BfMethodDef(); auto methodDef = new BfMethodDef();
mCurTypeDef->mMethods.push_back(methodDef); mCurTypeDef->mMethods.push_back(methodDef);
@ -2447,7 +2451,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
} }
} }
if (wantsToString) if ((wantsToString) && (!mCurTypeDef->mIsOpaque))
{ {
auto methodDef = new BfMethodDef(); auto methodDef = new BfMethodDef();
mCurTypeDef->mMethods.push_back(methodDef); mCurTypeDef->mMethods.push_back(methodDef);
@ -2463,7 +2467,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
methodDef->mAddedAfterEmit = mIsComptime; methodDef->mAddedAfterEmit = mIsComptime;
} }
if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL)) if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL) && (!mCurTypeDef->mIsOpaque))
{ {
auto methodDef = new BfMethodDef(); auto methodDef = new BfMethodDef();
mCurTypeDef->mMethods.push_back(methodDef); mCurTypeDef->mMethods.push_back(methodDef);
@ -2478,7 +2482,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
methodDef->mAddedAfterEmit = mIsComptime; methodDef->mAddedAfterEmit = mIsComptime;
} }
if ((needsEqualsMethod) && (strictEqualsMethod == NULL)) if ((needsEqualsMethod) && (strictEqualsMethod == NULL) && (!mCurTypeDef->mIsOpaque))
{ {
auto methodDef = new BfMethodDef(); auto methodDef = new BfMethodDef();
mCurTypeDef->mMethods.push_back(methodDef); mCurTypeDef->mMethods.push_back(methodDef);

View file

@ -5743,6 +5743,11 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
} }
} }
if ((resolvedFieldType->IsOpaque()) && (!IsInSpecializedGeneric()))
Fail(StrFormat("Invalid use of opaque type '%s' in field '%s.%s'",
TypeToString(resolvedFieldType).c_str(), TypeToString(mCurTypeInstance).c_str(), fieldDef->mName.c_str()),
fieldDef->mTypeRef, true);
if ((!typeInstance->IsSpecializedType()) && (!typeInstance->IsOnDemand()) && (fieldDef != NULL) && (!CheckDefineMemberProtection(fieldDef->mProtection, resolvedFieldType))) if ((!typeInstance->IsSpecializedType()) && (!typeInstance->IsOnDemand()) && (fieldDef != NULL) && (!CheckDefineMemberProtection(fieldDef->mProtection, resolvedFieldType)))
{ {
//CS0052 //CS0052

View file

@ -2751,7 +2751,9 @@ bool BfTypeInstance::IsValuelessType()
return false; return false;
} }
if (mTypeDef->mIsOpaque) if (mTypeDef->mIsOpaque)
return false; {
return true;
}
BF_ASSERT((mDefineState >= BfTypeDefineState_Defined) || (mTypeFailed)); BF_ASSERT((mDefineState >= BfTypeDefineState_Defined) || (mTypeFailed));
BF_ASSERT(mInstSize >= 0); BF_ASSERT(mInstSize >= 0);