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

Enhanced InferGenericArguments to include generic arg constraints

This commit is contained in:
Brian Fiete 2021-01-19 13:12:32 -08:00
parent b9c2d1b54f
commit 8f5f06bdb1

View file

@ -608,6 +608,22 @@ bool BfGenericInferContext::InferGenericArguments(BfMethodInstance* methodInstan
for (auto ifaceEntry : typeInstance->mInterfaces)
InferGenericArgument(methodInstance, ifaceEntry.mInterfaceType, ifaceConstraint, BfIRValue());
}
if (srcGenericArg->IsGenericParam())
{
auto genericParamType = (BfGenericParamType*)srcGenericArg;
BfGenericParamInstance* genericParam = NULL;
if (genericParamType->mGenericParamKind == BfGenericParamKind_Method)
genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericParamType->mGenericParamIdx];
else
genericParam = mModule->GetGenericParamInstance(genericParamType);
if (genericParam->mTypeConstraint != NULL)
InferGenericArgument(methodInstance, genericParam->mTypeConstraint, ifaceConstraint, BfIRValue());
for (auto argIfaceConstraint : genericParam->mInterfaceConstraints)
InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue());
}
}
}
@ -14440,11 +14456,13 @@ BfModuleMethodInstance BfExprEvaluator::GetSelectedMethod(BfAstNode* targetSrc,
if (genericArg == NULL)
{
failed = true;
mModule->Fail(StrFormat("Unable to determine generic argument '%s'", methodDef->mGenericParams[checkGenericIdx]->mName.c_str()).c_str(), targetSrc);
BfError* error = mModule->Fail(StrFormat("Unable to determine generic argument '%s'", methodDef->mGenericParams[checkGenericIdx]->mName.c_str()).c_str(), targetSrc);
if ((genericParam->mTypeConstraint != NULL) && (!genericParam->mTypeConstraint->IsUnspecializedType()))
genericArg = genericParam->mTypeConstraint;
else
genericArg = mModule->mContext->mBfObjectType;
if (error != NULL)
mModule->mCompiler->mPassInstance->MoreInfo(StrFormat("See method declaration"), unspecializedMethod->mMethodDef->GetRefNode());
}
}