Преглед изворни кода

mHadValidateErrors propagation fix

Brian Fiete пре 4 месеци
родитељ
комит
81a9478e77

+ 2 - 0
IDE/Tests/CompileFail001/src/Generics.bf

@@ -150,6 +150,8 @@ namespace IDETest
 			TestExt<int>.InnerB<int> c;
 			TestExt<int>.InnerC d;
 			TestExt<float>.InnerC e; //FAIL
+
+			List<String?> badArgType; //FAIL
 		}
 	}
 }

+ 1 - 0
IDEHelper/Compiler/BfModule.h

@@ -1846,6 +1846,7 @@ public:
 	bool AreConstraintsSubset(BfGenericParamInstance* checkInner, BfGenericParamInstance* checkOuter);
 	bool CheckConstraintState(BfAstNode* refNode);
 	void ValidateGenericParams(BfGenericParamKind genericParamKind, Span<BfGenericParamInstance*> genericParams);
+	void SetGenericValidationError(BfTypeInstance* typeInst);
 	bool ShouldAllowMultipleDefinitions(BfTypeInstance* typeInst, BfTypeDef* firstDeclaringTypeDef, BfTypeDef* secondDeclaringTypeDef);
 	void CheckInjectNewRevision(BfTypeInstance* typeInstance);
 	void InitType(BfType* resolvedTypeRef, BfPopulateType populateType);

+ 29 - 3
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -394,6 +394,26 @@ void BfModule::ValidateGenericParams(BfGenericParamKind genericParamKind, Span<B
 	}
 }
 
+void BfModule::SetGenericValidationError(BfTypeInstance* typeInst)
+{
+	if ((typeInst->mGenericTypeInfo == NULL) || (typeInst->mGenericTypeInfo->mHadValidateErrors))
+		return;
+	typeInst->mGenericTypeInfo->mHadValidateErrors = true;
+
+	for (auto depKV : typeInst->mDependencyMap)
+	{
+		auto depType = depKV.mKey;
+		auto depEntry = depKV.mValue;
+		if ((depEntry.mFlags & BfDependencyMap::DependencyFlag_TypeGenericArg) != 0)
+		{
+			BF_ASSERT(depType->IsGenericTypeInstance());
+
+			// If A<T> had validate errors then consider B<A<T>> to have validate errors
+			SetGenericValidationError(depType->ToTypeInstance());
+		}
+	}
+}
+
 bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* genericTypeInst, bool ignoreErrors)
 {
 	if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsTypeAlias()) && (mCurTypeInstance->IsGenericTypeInstance()))
@@ -421,7 +441,7 @@ bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* ge
 			mContext->mUnreifiedModule->PopulateType(underlyingType, BfPopulateType_Declaration);
 			bool result = ValidateGenericConstraints(typeRef, underlyingGenericType, ignoreErrors);
 			if (underlyingGenericType->mGenericTypeInfo->mHadValidateErrors)
-				genericTypeInst->mGenericTypeInfo->mHadValidateErrors = true;
+				SetGenericValidationError(genericTypeInst);
 			return result;
 		}
 		return true;
@@ -443,7 +463,7 @@ bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* ge
 		auto outerType = GetOuterType(genericTypeInst);
 		mContext->mUnreifiedModule->PopulateType(outerType, BfPopulateType_Declaration);
 		if ((outerType->mGenericTypeInfo != NULL) && (outerType->mGenericTypeInfo->mHadValidateErrors))
-			genericTypeInst->mGenericTypeInfo->mHadValidateErrors = true;
+			SetGenericValidationError(genericTypeInst);
 	}
 
 	for (int paramIdx = startGenericParamIdx; paramIdx < (int)genericTypeInst->mGenericTypeInfo->mGenericParams.size(); paramIdx++)
@@ -464,7 +484,7 @@ bool BfModule::ValidateGenericConstraints(BfAstNode* typeRef, BfTypeInstance* ge
 		if ((genericArg == NULL) || (!CheckGenericConstraints(BfGenericParamSource(genericTypeInst), genericArg, typeRef, genericParamInstance, NULL, &error)))
 		{
 			if (!genericTypeInst->IsUnspecializedTypeVariation())
-				genericTypeInst->mGenericTypeInfo->mHadValidateErrors = true;
+				SetGenericValidationError(genericTypeInst);
 			return false;
 		}
 	}
@@ -16051,6 +16071,12 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
 {
 	BP_ZONE("BfModule::DoTypeToString");
 
+	if (resolvedType == NULL)
+	{
+		str += "NULL";
+		return;
+	}
+
 	if (resolvedType->mContext == NULL)
 	{
 		str += "*UNINITIALIZED TYPE*";