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

Support System.Compiler values in comptime, SetReturnType, Enum helpers

This commit is contained in:
Brian Fiete 2022-06-23 11:53:21 -07:00
parent 0e86b5c49d
commit 2a55b5c7bb
14 changed files with 341 additions and 63 deletions

View file

@ -4328,6 +4328,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
ValidateGenericConstraints(validateEntry.mTypeRef, validateEntry.mGenericType, false);
}
bool isRootSystemType = typeInstance->IsInstanceOf(mCompiler->mValueTypeTypeDef) ||
typeInstance->IsInstanceOf(mCompiler->mAttributeTypeDef) ||
typeInstance->IsInstanceOf(mCompiler->mEnumTypeDef);
if (!typeInstance->IsBoxed())
{
if ((typeInstance->mCustomAttributes == NULL) && (typeDef->mTypeDeclaration != NULL) && (typeDef->HasCustomAttributes()))
@ -4696,7 +4700,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{
// Already handled
}
else if ((fieldDef != NULL) && (fieldDef->GetFieldDeclaration() != NULL) && (fieldDef->GetFieldDeclaration()->mAttributes != NULL) && (!typeInstance->mTypeFailed))
else if ((fieldDef != NULL) && (fieldDef->GetFieldDeclaration() != NULL) && (fieldDef->GetFieldDeclaration()->mAttributes != NULL) && (!typeInstance->mTypeFailed) && (!isRootSystemType))
{
if (auto propDecl = BfNodeDynCast<BfPropertyDeclaration>(fieldDef->mFieldDeclaration))
{
@ -4941,7 +4945,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
if (propDef->IsExpressionBodied())
target = (BfAttributeTargets)(target | BfAttributeTargets_Method);
if ((propDef->GetFieldDeclaration()->mAttributes != NULL) && (!typeInstance->mTypeFailed))
if ((propDef->GetFieldDeclaration()->mAttributes != NULL) && (!typeInstance->mTypeFailed) && (!isRootSystemType))
{
auto customAttrs = GetCustomAttributes(propDef->GetFieldDeclaration()->mAttributes, target);
delete customAttrs;
@ -5523,7 +5527,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
typeState.mCurTypeDef = propDef->mDeclaringType;
typeState.mType = typeInstance;
SetAndRestoreValue<BfTypeState*> prevTypeState(mContext->mCurTypeState, &typeState);
ResolveTypeRef(propDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowRef);
if (BfNodeIsA<BfVarTypeReference>(propDef->mTypeRef))
{
// This is only valid for ConstEval properties
}
else
ResolveTypeRef(propDef->mTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_AllowRef);
}
}
@ -14044,7 +14054,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
"Unable to cast '%s' to '%s'" :
"Unable to implicitly cast '%s' to '%s'";
String errStr = StrFormat(errStrF, TypeToString(typedVal.mType).c_str(), TypeToString(toType).c_str());
if ((castFlags & BfCastFlags_FromComptimeReturn) != 0)
errStrF = "Comptime return unable to cast '%s' to '%s'";
String errStr = StrFormat(errStrF, TypeToString(typedVal.mType).c_str(), TypeToString(toType).c_str());
auto error = Fail(errStr, srcNode);
if ((error != NULL) && (srcNode != NULL))
{