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

Fixed some constraint and generic type lifetime issues

This commit is contained in:
Brian Fiete 2020-06-03 12:07:58 -07:00
parent 88926da1ed
commit dacbcf4eb3
8 changed files with 145 additions and 47 deletions

View file

@ -415,11 +415,22 @@ bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstanc
return true;
}
auto typeInstance = argType->ToTypeInstance();
if (typeInstance == NULL)
return true;
if (wantGenericType->IsInterface())
{
for (auto& ifaceEntry : typeInstance->mInterfaces)
InferGenericArgument(methodInstance, ifaceEntry.mInterfaceType, wantType, BfIRValue());
}
else if (typeInstance->mBaseType != NULL)
InferGenericArgument(methodInstance, typeInstance->mBaseType, wantType, BfIRValue());
if (!argType->IsGenericTypeInstance())
return true;
auto argGenericType = (BfGenericTypeInstance*)argType;
if (argGenericType->mTypeDef != wantGenericType->mTypeDef)
return false;
return true;
for (int genericArgIdx = 0; genericArgIdx < (int)argGenericType->mTypeGenericArguments.size(); genericArgIdx++)
{
@ -1546,7 +1557,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
auto wantType = methodInstance->GetParamType(paramIdx);
if ((genericArgumentsSubstitute != NULL) && (wantType->IsUnspecializedType()))
{
auto resolvedType = mModule->ResolveGenericType(wantType, NULL, genericArgumentsSubstitute);
auto resolvedType = mModule->ResolveGenericType(wantType, NULL, genericArgumentsSubstitute, false);
if (resolvedType == NULL)
goto NoMatch;
wantType = resolvedType;
@ -2164,7 +2175,7 @@ void BfMethodMatcher::TryDevirtualizeCall(BfTypedValue target, BfTypedValue* ori
auto useModule = mModule->mContext->mUnreifiedModule;
boxedType = useModule->CreateBoxedType(target.mType);
useModule->PopulateType(boxedType, BfPopulateType_DataAndMethods);
useModule->AddDependency(boxedType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_Calls);
useModule->AddDependency(boxedType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_WeakReference);
}
else
{
@ -12739,8 +12750,9 @@ BfModuleMethodInstance BfExprEvaluator::GetSelectedMethod(BfAstNode* targetSrc,
else
paramSrc = methodMatcher.mArguments[methodMatcher.mBestMethodGenericArgumentSrcs[checkGenericIdx]].mExpression;
// Note: don't pass methodMatcher.mBestMethodGenericArguments into here, this method is already specialized
BfError* error = NULL;
if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance.mMethodInstance), genericArg, paramSrc, genericParams[checkGenericIdx], &methodMatcher.mBestMethodGenericArguments,
if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance.mMethodInstance), genericArg, paramSrc, genericParams[checkGenericIdx], NULL,
failed ? NULL : &error))
{
if (methodInstance.mMethodInstance->IsSpecializedGenericMethod())