Browse Source

Fixed missing generic type validation errors with elemented types

Brian Fiete 4 years ago
parent
commit
733f7ec983

+ 1 - 1
IDEHelper/Compiler/BfModule.cpp

@@ -6543,7 +6543,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
 				
 		BfIRValue methodNameConst = GetStringObjectValue(methodDef->mName, true);
 						
-		BfMethodFlags methodFlags = moduleMethodInstance.mMethodInstance->GetMethodFlags();
+		BfMethodFlags methodFlags = defaultMethod->GetMethodFlags();
 		
 		int customAttrIdx = _HandleCustomAttrs(methodCustomAttributes);
 

+ 2 - 1
IDEHelper/Compiler/BfModule.h

@@ -1808,6 +1808,7 @@ public:
 	BfTypeInstance* GetBaseType(BfTypeInstance* typeInst);
 	void HandleTypeGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, int typeGenericParamIdx);
 	void HandleMethodGenericParamRef(BfAstNode* refNode, BfTypeDef* typeDef, BfMethodDef* methodDef, int typeGenericParamIdx);
+	bool ResolveTypeResult_Validate(BfTypeReference* typeRef, BfType* resolvedTypeRef);
 	BfType* ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags);
 	void ShowAmbiguousTypeError(BfAstNode* refNode, BfTypeDef* typeDef, BfTypeDef* otherTypeDef);
 	void ShowGenericArgCountError(BfTypeReference* typeRef, int wantedGenericParams);	
@@ -1820,7 +1821,7 @@ public:
 	void CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName = NULL);
 	void CheckIdentifierFixit(BfAstNode* node);
 	void TypeRefNotFound(BfTypeReference* typeRef, const char* appendName = NULL);
-	bool ValidateTypeWildcard(BfTypeReference* typeRef, bool isAttributeRef);
+	bool ValidateTypeWildcard(BfTypeReference* typeRef, bool isAttributeRef);	
 	BfType* ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0, int numGenericArgs = 0);
 	BfType* ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool resolveGenericParam = true);
 	BfType* ResolveTypeRef(BfAstNode* astNode, const BfSizedArray<BfTypeReference*>* genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);

+ 59 - 30
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -7695,6 +7695,63 @@ BfGenericParamInstance* BfModule::GetGenericParamInstance(BfGenericParamType* ty
 	return GetGenericTypeParamInstance(type->mGenericParamIdx);
 }
 
+bool BfModule::ResolveTypeResult_Validate(BfTypeReference* typeRef, BfType* resolvedTypeRef)
+{
+	if ((typeRef == NULL) || (resolvedTypeRef == NULL))
+		return true;
+
+	BfTypeInstance* genericTypeInstance = resolvedTypeRef->ToGenericTypeInstance();
+	
+	if ((genericTypeInstance != NULL) && (genericTypeInstance != mCurTypeInstance))
+	{
+		bool doValidate = (genericTypeInstance->mGenericTypeInfo->mHadValidateErrors) ||
+			(!genericTypeInstance->mGenericTypeInfo->mValidatedGenericConstraints) ||
+			(genericTypeInstance->mGenericTypeInfo->mIsUnspecializedVariation);
+		if ((mCurMethodInstance != NULL) && (mCurMethodInstance->IsOrInUnspecializedVariation()))
+			doValidate = false;
+		if (mCurTypeInstance != NULL)
+		{
+			if (mCurTypeInstance->IsUnspecializedTypeVariation())
+				doValidate = false;
+			if (auto curGenericTypeInstance = mCurTypeInstance->ToGenericTypeInstance())
+			{
+				if ((curGenericTypeInstance->mDependencyMap.mMinDependDepth > 32) &&
+					(genericTypeInstance->mDependencyMap.mMinDependDepth > 32))
+				{
+					Fail(StrFormat("Generic type dependency depth exceeded for type '{}'", TypeToString(genericTypeInstance).c_str()), typeRef);
+					return false;
+				}
+
+				if (curGenericTypeInstance->mGenericTypeInfo->mHadValidateErrors)
+					doValidate = false;
+			}
+			if ((mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mCurBaseTypeRef != NULL) && (!mContext->mCurTypeState->mTypeInstance->IsTypeAlias())) // We validate constraints for base types later
+				doValidate = false;
+		}
+
+		if (doValidate)
+			ValidateGenericConstraints(typeRef, genericTypeInstance, false);
+	}
+
+	if (auto genericInstanceTypeRef = BfNodeDynCastExact<BfGenericInstanceTypeRef>(typeRef))
+	{
+		if (genericTypeInstance != NULL)
+		{
+			auto genericTypeInfo = genericTypeInstance->GetGenericTypeInfo();			
+			for (int argIdx = 0; argIdx < (int)genericInstanceTypeRef->mGenericArguments.size(); argIdx++)
+			{
+				ResolveTypeResult_Validate(genericInstanceTypeRef->mGenericArguments[argIdx], genericTypeInfo->mTypeGenericArguments[argIdx]);
+			}
+		}
+	}	
+	else if (auto elementedTypeRef = BfNodeDynCast<BfElementedTypeRef>(typeRef))
+	{
+		return ResolveTypeResult_Validate(elementedTypeRef, resolvedTypeRef->GetUnderlyingType());
+	}
+
+	return true;
+}
+
 BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
 {
 	if ((mCompiler->mIsResolveOnly) && (!IsInSpecializedSection()))
@@ -7946,36 +8003,8 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
 	
 	populateModule->PopulateType(resolvedTypeRef, populateType);
 	
-	if ((genericTypeInstance != NULL) && (genericTypeInstance != mCurTypeInstance) && (populateType > BfPopulateType_Identity))
-	{
-		bool doValidate = (genericTypeInstance->mGenericTypeInfo->mHadValidateErrors) || 
-			(!genericTypeInstance->mGenericTypeInfo->mValidatedGenericConstraints) || 
-			(genericTypeInstance->mGenericTypeInfo->mIsUnspecializedVariation);
-		if ((mCurMethodInstance != NULL) && (mCurMethodInstance->IsOrInUnspecializedVariation()))
-			doValidate = false;
-		if (mCurTypeInstance != NULL)
-		{
-			if (mCurTypeInstance->IsUnspecializedTypeVariation())
-				doValidate = false;
-			if (auto curGenericTypeInstance = mCurTypeInstance->ToGenericTypeInstance())
-			{
-				if ((curGenericTypeInstance->mDependencyMap.mMinDependDepth > 32) &&
-					(genericTypeInstance->mDependencyMap.mMinDependDepth > 32))
-				{
-					Fail(StrFormat("Generic type dependency depth exceeded for type '{}'", TypeToString(genericTypeInstance).c_str()), typeRef);
-					return NULL;
-				}
-
-				if (curGenericTypeInstance->mGenericTypeInfo->mHadValidateErrors)
-					doValidate = false;
-			}
-			if ((mContext->mCurTypeState != NULL) && (mContext->mCurTypeState->mCurBaseTypeRef != NULL) && (!mContext->mCurTypeState->mTypeInstance->IsTypeAlias())) // We validate constraints for base types later
-				doValidate = false;
-		}
-
-		if (doValidate)
-			ValidateGenericConstraints(typeRef, genericTypeInstance, false);
-	}
+	if ((populateType > BfPopulateType_Identity) && (!ResolveTypeResult_Validate(typeRef, resolvedTypeRef)))
+		return NULL;	
 	
 	if (populateType != BfPopulateType_IdentityNoRemapAlias)
 	{