From 4b2256d41e3d4f5c0ebe68f354f26af46d8ac63a Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 28 Apr 2020 07:30:10 -0700 Subject: [PATCH] Added some warnings for nullable(T) usage --- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 93a6fac5..9206d1f3 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -7228,11 +7228,22 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula typeVec.push_back(resolvedType); resolvedType = ResolveTypeDef(mCompiler->mNullableTypeDef, typeVec, BfPopulateType_Declaration); } - else if ((resolvedType != NULL) && (resolvedType->IsValueType())) - { - BfTypeVector typeVec; - typeVec.push_back(resolvedType); - resolvedType = ResolveTypeDef(mCompiler->mNullableTypeDef, typeVec, BfPopulateType_Declaration); + else if (resolvedType != NULL) + { + if (resolvedType->IsValueType()) + { + if (InDefinitionSection()) + Warn(0, StrFormat("Consider using '%s?' instead of nullable modifier", TypeToString(resolvedType).c_str()), retTypeTypeRef); + + BfTypeVector typeVec; + typeVec.push_back(resolvedType); + resolvedType = ResolveTypeDef(mCompiler->mNullableTypeDef, typeVec, BfPopulateType_Declaration); + } + else + { + if (InDefinitionSection()) + Warn(0, StrFormat("Unneeded nullable modifier, %s is already nullable", TypeToString(resolvedType).c_str()), retTypeTypeRef->mRetTypeToken); + } } if (resolvedType != NULL) PopulateType(resolvedType, populateType);