فهرست منبع

Improved issues with enums with code emissions

Brian Fiete 11 ماه پیش
والد
کامیت
35271626aa

+ 7 - 1
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -9117,7 +9117,7 @@ BfTypedValue BfExprEvaluator::CheckEnumCreation(BfAstNode* targetSrc, BfTypeInst
 
 			if (wantConst)
 			{
-				NOP;
+				//
 			}
 			else if ((mReceivingValue != NULL) && (mReceivingValue->mType == enumType) && (mReceivingValue->IsAddr()))
 			{
@@ -9136,6 +9136,12 @@ BfTypedValue BfExprEvaluator::CheckEnumCreation(BfAstNode* targetSrc, BfTypeInst
 			auto tupleType = (BfTypeInstance*)fieldInstance->mResolvedType;
 			mModule->mBfIRBuilder->PopulateType(tupleType);
 
+			if (tupleType->IsDeleting())
+			{
+				mModule->FailInternal("Deleted tuple type found in CheckEnumCreation", targetSrc);
+				return BfTypedValue();
+			}
+
 			bool constFailed = false;
 			SizedArray<BfIRValue, 8> constTupleMembers;
 			BfIRValue fieldPtr;

+ 2 - 1
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -3931,7 +3931,8 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 		if ((typeInstance->mRebuildFlags & BfTypeRebuildFlag_UnderlyingTypeDeferred) != 0)
 			underlyingTypeDeferred = true;
 	}
-	else if (typeInstance->IsEnum())
+	
+	if ((typeInstance->IsEnum()) && (underlyingType == NULL) && (!underlyingTypeDeferred))
 	{
 		bool hasPayloads = false;
 		for (auto fieldDef : typeDef->mFields)

+ 10 - 4
IDEHelper/Compiler/BfResolvedTypeUtils.cpp

@@ -2691,14 +2691,20 @@ BfType* BfTypeInstance::GetUnderlyingType()
 	{
 		if (!checkTypeInst->mFieldInstances.empty())
 		{
-			mTypeInfoEx->mUnderlyingType = checkTypeInst->mFieldInstances.back().mResolvedType;
-			return mTypeInfoEx->mUnderlyingType;
+			auto& lastField = checkTypeInst->mFieldInstances.back();
+			if (lastField.mFieldIdx == -1)
+			{
+				auto underlyingType = lastField.mResolvedType;
+				BF_ASSERT(underlyingType != this);
+				mTypeInfoEx->mUnderlyingType = underlyingType;
+				return mTypeInfoEx->mUnderlyingType;
+			}
 		}
 		checkTypeInst = checkTypeInst->mBaseType;
-		if (checkTypeInst->IsIncomplete())
+		if ((checkTypeInst != NULL) && (checkTypeInst->IsIncomplete()))
 			mModule->PopulateType(checkTypeInst, BfPopulateType_Data);
 	}
-	BF_FATAL("Failed");
+	//BF_FATAL("Failed");
 	return mTypeInfoEx->mUnderlyingType;
 }