1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fix for test methods on generic types

This commit is contained in:
Brian Fiete 2020-02-24 05:42:41 -08:00
parent 2bcfdcc06c
commit e962a1a339
2 changed files with 36 additions and 10 deletions

View file

@ -791,10 +791,24 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array<TestMethod>& 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()),
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;
}
@ -803,9 +817,12 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array<TestMethod>& test
{
if ((methodInstance->GetParamInitializer(0) == NULL) &&
(methodInstance->GetParamKind(0) != BfParamKind_Params))
{
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,15 +848,16 @@ void BfCompiler::GetTestMethods(BfVDataModule* bfModule, Array<TestMethod>& test
if (typeInstance == NULL)
continue;
if (typeInstance->IsUnspecializedType())
continue;
for (auto& methodInstanceGroup : typeInstance->mMethodInstanceGroups)
{
if (methodInstanceGroup.mDefault != NULL)
{
_CheckMethod(typeInstance, methodInstanceGroup.mDefault);
}
}
}
}
void BfCompiler::EmitTestMethod(BfVDataModule* bfModule, Array<TestMethod>& testMethods, BfIRValue& retValue)
{

View file

@ -9232,6 +9232,14 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
if (type->IsUnspecializedType())
type = ResolveGenericType(type, *methodGenericArgs);
}
if ((methodGenericArgs == NULL) && (mCurMethodInstance == NULL) && (mCurTypeInstance == NULL))
{
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, methodInst->GetOwner());
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, methodInst);
methodName += TypeToString(type, typeNameFlags);
}
else
methodName += TypeToString(type, typeNameFlags);
}
methodName += ">";