From e962a1a3396020b660f2f6b7dc57399110e6bbc6 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 24 Feb 2020 05:42:41 -0800 Subject: [PATCH] Fix for test methods on generic types --- IDEHelper/Compiler/BfCompiler.cpp | 34 +++++++++++++++++++++++-------- IDEHelper/Compiler/BfModule.cpp | 12 +++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index ea119357..02b4c178 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -791,10 +791,24 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test if (!isTest) return; + if (methodInstance->mIsUnspecialized) + { + if (!typeInstance->IsSpecializedType()) + { + bfModule->Fail(StrFormat("Method '%s' cannot be used for testing because it's generic", bfModule->MethodToString(methodInstance).c_str()), + methodInstance->mMethodDef->GetRefNode()); + } + bfModule->mHadBuildError = true; + return; + } + if (!methodInstance->mMethodDef->mIsStatic) { - bfModule->Fail(StrFormat("Method '%s' cannot be used for testing because it is not static", bfModule->MethodToString(methodInstance).c_str()), - methodInstance->mMethodDef->GetRefNode()); + if (!typeInstance->IsSpecializedType()) + { + bfModule->Fail(StrFormat("Method '%s' cannot be used for testing because it's not static", bfModule->MethodToString(methodInstance).c_str()), + methodInstance->mMethodDef->GetRefNode()); + } bfModule->mHadBuildError = true; return; } @@ -804,8 +818,11 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test if ((methodInstance->GetParamInitializer(0) == NULL) && (methodInstance->GetParamKind(0) != BfParamKind_Params)) { - bfModule->Fail(StrFormat("Method '%s' cannot be used for testing because it contains parameters without defaults", bfModule->MethodToString(methodInstance).c_str()), - methodInstance->mMethodDef->GetRefNode()); + if (!typeInstance->IsSpecializedType()) + { + bfModule->Fail(StrFormat("Method '%s' cannot be used for testing because it contains parameters without defaults", bfModule->MethodToString(methodInstance).c_str()), + methodInstance->mMethodDef->GetRefNode()); + } bfModule->mHadBuildError = true; return; } @@ -831,12 +848,13 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array& test if (typeInstance == NULL) continue; + if (typeInstance->IsUnspecializedType()) + continue; + for (auto& methodInstanceGroup : typeInstance->mMethodInstanceGroups) { - if (methodInstanceGroup.mDefault != NULL) - { - _CheckMethod(typeInstance, methodInstanceGroup.mDefault); - } + if (methodInstanceGroup.mDefault != NULL) + _CheckMethod(typeInstance, methodInstanceGroup.mDefault); } } } diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 2440e03e..41f0988b 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -9231,8 +9231,16 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags if (type->IsUnspecializedType()) type = ResolveGenericType(type, *methodGenericArgs); - } - methodName += TypeToString(type, typeNameFlags); + } + + if ((methodGenericArgs == NULL) && (mCurMethodInstance == NULL) && (mCurTypeInstance == NULL)) + { + SetAndRestoreValue prevTypeInstance(mCurTypeInstance, methodInst->GetOwner()); + SetAndRestoreValue prevMethodInstance(mCurMethodInstance, methodInst); + methodName += TypeToString(type, typeNameFlags); + } + else + methodName += TypeToString(type, typeNameFlags); } methodName += ">"; }