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

Fixed some generic param cases with generic methods in generic variants

This commit is contained in:
Brian Fiete 2021-01-01 15:33:00 -08:00
parent 4f3c28ef2f
commit 06a1ea841f
5 changed files with 74 additions and 21 deletions

View file

@ -17,6 +17,24 @@ namespace IDETest
} }
} }
class ClassT<T>
{
public void Test<T2>(T t, T2 t2)
{
}
public void Test<T2>(T t, T2 t2) //FAIL
{
}
}
public static void Boing<TA, TB, TC>()
{
ClassT<TC>.Test<TB>(default, default); //FAIL 'IDETest.Methods.ClassT<TC>.Test<TB>(TC t, TB t2)' is a candidate
}
public static void MethodA(ClassA zong, int arg) public static void MethodA(ClassA zong, int arg)
{ {

View file

@ -2444,7 +2444,16 @@ namespace IDE
{ {
bool foundErrorText = false; bool foundErrorText = false;
if (var error = FindError(lineIdx)) if (var error = FindError(lineIdx))
foundErrorText = error.mError.Contains(wantsError); {
if (error.mError.Contains(wantsError))
foundErrorText = true;
if (error.mMoreInfo != null)
{
for (var moreInfo in error.mMoreInfo)
if (moreInfo.mError.Contains(wantsError))
foundErrorText = true;
}
}
if (!foundErrorText) if (!foundErrorText)
{ {
mScriptManager.Fail("Error at line {0} in {1} did not contain error text '{2}'\n\t", lineIdx + 1, textPanel.mFilePath, wantsError); mScriptManager.Fail("Error at line {0} in {1} did not contain error text '{2}'\n\t", lineIdx + 1, textPanel.mFilePath, wantsError);

View file

@ -932,6 +932,9 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
paramDiff = (int) newMethodInstance->GetParamCount() - (int) prevMethodInstance->GetParamCount(); paramDiff = (int) newMethodInstance->GetParamCount() - (int) prevMethodInstance->GetParamCount();
RETURN_BETTER_OR_WORSE(paramDiff < 0, paramDiff > 0); RETURN_BETTER_OR_WORSE(paramDiff < 0, paramDiff > 0);
BfMethodInstance* typeUnspecNewMethodInstance = mModule->GetUnspecializedMethodInstance(newMethodInstance, true);
BfMethodInstance* typeUnspecPrevMethodInstance = mModule->GetUnspecializedMethodInstance(prevMethodInstance, true);
// Check specificity of args // Check specificity of args
std::function<void(BfType*, BfType*)> _CompareParamTypes = [&](BfType* newType, BfType* prevType) std::function<void(BfType*, BfType*)> _CompareParamTypes = [&](BfType* newType, BfType* prevType)
@ -942,8 +945,8 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
auto prevGenericParamType = (BfGenericParamType*)prevType; auto prevGenericParamType = (BfGenericParamType*)prevType;
if ((newGenericParamType->mGenericParamKind == BfGenericParamKind_Method) && (prevGenericParamType->mGenericParamKind == BfGenericParamKind_Method)) if ((newGenericParamType->mGenericParamKind == BfGenericParamKind_Method) && (prevGenericParamType->mGenericParamKind == BfGenericParamKind_Method))
{ {
auto newMethodGenericParam = newMethodInstance->mMethodInfoEx->mGenericParams[newGenericParamType->mGenericParamIdx]; auto newMethodGenericParam = typeUnspecNewMethodInstance->mMethodInfoEx->mGenericParams[newGenericParamType->mGenericParamIdx];
auto prevMethodGenericParam = prevMethodInstance->mMethodInfoEx->mGenericParams[prevGenericParamType->mGenericParamIdx]; auto prevMethodGenericParam = typeUnspecPrevMethodInstance->mMethodInfoEx->mGenericParams[prevGenericParamType->mGenericParamIdx];
SET_BETTER_OR_WORSE(mModule->AreConstraintsSubset(prevMethodGenericParam, newMethodGenericParam), mModule->AreConstraintsSubset(newMethodGenericParam, prevMethodGenericParam)); SET_BETTER_OR_WORSE(mModule->AreConstraintsSubset(prevMethodGenericParam, newMethodGenericParam), mModule->AreConstraintsSubset(newMethodGenericParam, prevMethodGenericParam));
} }
} }
@ -973,7 +976,7 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
{ {
int newArgIdx = argIdx + newImplicitParamCount; int newArgIdx = argIdx + newImplicitParamCount;
int prevArgIdx = argIdx + prevImplicitParamCount; int prevArgIdx = argIdx + prevImplicitParamCount;
_CompareParamTypes(newMethodInstance->GetParamType(newArgIdx), prevMethodInstance->GetParamType(prevArgIdx)); _CompareParamTypes(typeUnspecNewMethodInstance->GetParamType(newArgIdx), typeUnspecPrevMethodInstance->GetParamType(prevArgIdx));
} }
// Do generic constraint subset test directly to handle cases like "NotDisposed<T>()" vs "NotDisposed<T>() where T : IDisposable" // Do generic constraint subset test directly to handle cases like "NotDisposed<T>()" vs "NotDisposed<T>() where T : IDisposable"
@ -1392,6 +1395,10 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
BFMODULE_FATAL(mModule, "Failed to get raw method in BfMethodMatcher::CheckMethod"); BFMODULE_FATAL(mModule, "Failed to get raw method in BfMethodMatcher::CheckMethod");
return false; return false;
} }
BfMethodInstance* typeUnspecMethodInstance = mModule->GetUnspecializedMethodInstance(methodInstance, true);
BfTypeVector* typeGenericArguments = NULL;
if (typeInstance->mGenericTypeInfo != NULL)
typeGenericArguments = &typeInstance->mGenericTypeInfo->mTypeGenericArguments;
if ((mInterfaceMethodInstance != NULL) && (methodInstance->GetExplicitInterface() != NULL)) if ((mInterfaceMethodInstance != NULL) && (methodInstance->GetExplicitInterface() != NULL))
{ {
@ -1773,7 +1780,8 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
auto wantType = methodInstance->GetParamType(paramIdx); auto wantType = methodInstance->GetParamType(paramIdx);
if ((genericArgumentsSubstitute != NULL) && (wantType->IsUnspecializedType())) if ((genericArgumentsSubstitute != NULL) && (wantType->IsUnspecializedType()))
{ {
auto resolvedType = mModule->ResolveGenericType(wantType, NULL, genericArgumentsSubstitute, false); wantType = typeUnspecMethodInstance->GetParamType(paramIdx);
auto resolvedType = mModule->ResolveGenericType(wantType, typeGenericArguments, genericArgumentsSubstitute, false);
if (resolvedType == NULL) if (resolvedType == NULL)
goto NoMatch; goto NoMatch;
wantType = resolvedType; wantType = resolvedType;
@ -2039,15 +2047,27 @@ void BfMethodMatcher::FlushAmbiguityError()
error = mModule->Fail("Ambiguous method call", mTargetSrc); error = mModule->Fail("Ambiguous method call", mTargetSrc);
if (error != NULL) if (error != NULL)
{ {
BfMethodInstance* bestMethodInstance = mModule->GetRawMethodInstance(mBestMethodTypeInstance, mBestMethodDef); auto unspecializedType = mModule->GetUnspecializedTypeInstance(mBestMethodTypeInstance);
BfMethodInstance* bestMethodInstance = mModule->GetRawMethodInstance(unspecializedType, mBestMethodDef);
BfTypeVector* typeGenericArguments = NULL;
if (mBestMethodTypeInstance->mGenericTypeInfo != NULL)
typeGenericArguments = &mBestMethodTypeInstance->mGenericTypeInfo->mTypeGenericArguments;
mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' is a candidate", mModule->MethodToString(bestMethodInstance, BfMethodNameFlag_ResolveGenericParamNames, mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' is a candidate", mModule->MethodToString(bestMethodInstance, BfMethodNameFlag_ResolveGenericParamNames,
mBestMethodGenericArguments.empty() ? NULL : &mBestMethodGenericArguments).c_str()), typeGenericArguments, mBestMethodGenericArguments.empty() ? NULL : &mBestMethodGenericArguments).c_str()),
bestMethodInstance->mMethodDef->GetRefNode()); bestMethodInstance->mMethodDef->GetRefNode());
for (auto& ambiguousEntry : mAmbiguousEntries) for (auto& ambiguousEntry : mAmbiguousEntries)
{ {
mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' is a candidate", mModule->MethodToString(ambiguousEntry.mMethodInstance, BfMethodNameFlag_ResolveGenericParamNames, auto typeInstance = ambiguousEntry.mMethodInstance->GetOwner();
ambiguousEntry.mBestMethodGenericArguments.empty() ? NULL : &ambiguousEntry.mBestMethodGenericArguments).c_str()), auto unspecTypeMethodInstance = mModule->GetUnspecializedMethodInstance(ambiguousEntry.mMethodInstance, true);
BfTypeVector* typeGenericArguments = NULL;
if (typeInstance->mGenericTypeInfo != NULL)
typeGenericArguments = &typeInstance->mGenericTypeInfo->mTypeGenericArguments;
mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("'%s' is a candidate", mModule->MethodToString(unspecTypeMethodInstance, BfMethodNameFlag_ResolveGenericParamNames,
typeGenericArguments, ambiguousEntry.mBestMethodGenericArguments.empty() ? NULL : &ambiguousEntry.mBestMethodGenericArguments).c_str()),
ambiguousEntry.mMethodInstance->mMethodDef->GetRefNode()); ambiguousEntry.mMethodInstance->mMethodDef->GetRefNode());
} }
} }
@ -9435,6 +9455,10 @@ bool BfExprEvaluator::LookupTypeProp(BfTypeOfExpression* typeOfExpr, BfIdentifie
_BoolResult(type->IsNullable()); _BoolResult(type->IsNullable());
else if (memberName == "IsGenericType") else if (memberName == "IsGenericType")
_BoolResult(type->IsGenericTypeInstance()); _BoolResult(type->IsGenericTypeInstance());
else if (memberName == "IsArray")
_BoolResult(type->IsArray());
else if (memberName == "IsSizedArray")
_BoolResult(type->IsSizedArray());
else if (memberName == "TypeId") else if (memberName == "TypeId")
_Int32Result(type->mTypeId); _Int32Result(type->mTypeId);
else if (memberName == "GenericParamCount") else if (memberName == "GenericParamCount")

View file

@ -9750,7 +9750,7 @@ BfMethodInstance* BfModule::GetUnspecializedMethodInstance(BfMethodInstance* met
BF_ASSERT(!owner->IsTuple()); BF_ASSERT(!owner->IsTuple());
auto genericType = (BfTypeInstance*)owner; auto genericType = (BfTypeInstance*)owner;
if (genericType->IsUnspecializedType()) if ((genericType->IsUnspecializedType()) && (!genericType->IsUnspecializedTypeVariation()))
return methodInstance; return methodInstance;
auto unspecializedType = ResolveTypeDef(genericType->mTypeDef); auto unspecializedType = ResolveTypeDef(genericType->mTypeDef);
@ -10113,16 +10113,18 @@ bool BfModule::HasMixin(BfTypeInstance* typeInstance, const StringImpl& methodNa
return BfModuleMethodInstance(); return BfModuleMethodInstance();
} }
StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags, BfTypeVector* methodGenericArgs) StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags, BfTypeVector* typeGenericArgs, BfTypeVector* methodGenericArgs)
{ {
auto methodDef = methodInst->mMethodDef; auto methodDef = methodInst->mMethodDef;
bool allowResolveGenericParamNames = ((methodNameFlags & BfMethodNameFlag_ResolveGenericParamNames) != 0); bool allowResolveGenericParamNames = ((methodNameFlags & BfMethodNameFlag_ResolveGenericParamNames) != 0);
BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None; BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None;
bool hasGenericArgs = (typeGenericArgs != NULL) || (methodGenericArgs != NULL);
BfType* type = methodInst->mMethodInstanceGroup->mOwner; BfType* type = methodInst->mMethodInstanceGroup->mOwner;
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType())) if ((hasGenericArgs) && (type->IsUnspecializedType()))
type = ResolveGenericType(type, NULL, methodGenericArgs); type = ResolveGenericType(type, typeGenericArgs, methodGenericArgs);
if ((type == NULL) || (!type->IsUnspecializedTypeVariation())) if ((type == NULL) || (!type->IsUnspecializedTypeVariation()))
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if (allowResolveGenericParamNames) if (allowResolveGenericParamNames)
@ -10135,8 +10137,8 @@ StringT<128> BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodName
auto typeNameFlags = BfTypeNameFlags_None; auto typeNameFlags = BfTypeNameFlags_None;
if (allowResolveGenericParamNames) if (allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if ((methodGenericArgs != NULL) && (type->IsUnspecializedType())) if ((hasGenericArgs) && (type->IsUnspecializedType()))
type = ResolveGenericType(type, NULL, methodGenericArgs); type = ResolveGenericType(type, typeGenericArgs, methodGenericArgs);
methodName += TypeToString(type, typeNameFlags); methodName += TypeToString(type, typeNameFlags);
}; };

View file

@ -1516,7 +1516,7 @@ public:
StringT<128> TypeToString(BfType* resolvedType, Array<String>* genericMethodParamNameOverrides = NULL); StringT<128> TypeToString(BfType* resolvedType, Array<String>* genericMethodParamNameOverrides = NULL);
StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array<String>* genericMethodParamNameOverrides = NULL); StringT<128> TypeToString(BfType* resolvedType, BfTypeNameFlags typeNameFlags, Array<String>* genericMethodParamNameOverrides = NULL);
void DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None, Array<String>* genericMethodParamNameOverrides = NULL); void DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None, Array<String>* genericMethodParamNameOverrides = NULL);
StringT<128> MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags = BfMethodNameFlag_ResolveGenericParamNames, BfTypeVector* methodGenericArgs = NULL); StringT<128> MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags methodNameFlags = BfMethodNameFlag_ResolveGenericParamNames, BfTypeVector* typeGenericArgs = NULL, BfTypeVector* methodGenericArgs = NULL);
void pv(BfType* type); void pv(BfType* type);
void CurrentAddToConstHolder(BfIRValue& irVal); void CurrentAddToConstHolder(BfIRValue& irVal);
void ClearConstData(); void ClearConstData();