mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Improvements to generic inference with params
This commit is contained in:
parent
10e8136a9c
commit
0d0d98f6d6
1 changed files with 15 additions and 1 deletions
|
@ -1736,6 +1736,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
||||||
|
|
||||||
bool hadInferFailure = false;
|
bool hadInferFailure = false;
|
||||||
int inferParamOffset = paramOfs - argIdx;
|
int inferParamOffset = paramOfs - argIdx;
|
||||||
|
int paramsParamIdx = -1;
|
||||||
|
|
||||||
enum ResultKind
|
enum ResultKind
|
||||||
{
|
{
|
||||||
|
@ -1747,6 +1748,9 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
||||||
auto _CheckArg = [&](int argIdx)
|
auto _CheckArg = [&](int argIdx)
|
||||||
{
|
{
|
||||||
paramIdx = argIdx + inferParamOffset;
|
paramIdx = argIdx + inferParamOffset;
|
||||||
|
if ((paramsParamIdx != -1) && (paramIdx > paramsParamIdx))
|
||||||
|
paramIdx = paramsParamIdx;
|
||||||
|
|
||||||
auto wantType = methodInstance->GetParamType(paramIdx);
|
auto wantType = methodInstance->GetParamType(paramIdx);
|
||||||
|
|
||||||
auto checkType = wantType;
|
auto checkType = wantType;
|
||||||
|
@ -1814,6 +1818,13 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
||||||
if (type->IsVar())
|
if (type->IsVar())
|
||||||
mHasVarArguments = true;
|
mHasVarArguments = true;
|
||||||
|
|
||||||
|
if (methodInstance->GetParamKind(paramIdx) == BfParamKind_Params)
|
||||||
|
{
|
||||||
|
paramsParamIdx = paramIdx;
|
||||||
|
if ((wantType->IsArray()) || (wantType->IsInstanceOf(mModule->mCompiler->mSpanTypeDef)))
|
||||||
|
wantType = wantType->GetUnderlyingType();
|
||||||
|
}
|
||||||
|
|
||||||
genericInferContext.mCheckedTypeSet.Clear();
|
genericInferContext.mCheckedTypeSet.Clear();
|
||||||
if (!genericInferContext.InferGenericArgument(methodInstance, type, wantType, argTypedValue.mValue))
|
if (!genericInferContext.InferGenericArgument(methodInstance, type, wantType, argTypedValue.mValue))
|
||||||
return ResultKind_Failed;
|
return ResultKind_Failed;
|
||||||
|
@ -1825,7 +1836,7 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
||||||
for (; argIdx < (int)mArguments.size(); argIdx++)
|
for (; argIdx < (int)mArguments.size(); argIdx++)
|
||||||
{
|
{
|
||||||
paramIdx = argIdx + inferParamOffset;
|
paramIdx = argIdx + inferParamOffset;
|
||||||
if (paramIdx >= paramCount)
|
if ((paramIdx >= paramCount) && (paramsParamIdx == -1))
|
||||||
break; // Possible for delegate 'params' type methods
|
break; // Possible for delegate 'params' type methods
|
||||||
|
|
||||||
auto resultKind = _CheckArg(argIdx);
|
auto resultKind = _CheckArg(argIdx);
|
||||||
|
@ -1963,6 +1974,9 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
|
||||||
auto paramsArrayType = methodInstance->GetParamType(paramIdx);
|
auto paramsArrayType = methodInstance->GetParamType(paramIdx);
|
||||||
paramsArrayType = mModule->ResolveGenericType(paramsArrayType, NULL, genericArgumentsSubstitute);
|
paramsArrayType = mModule->ResolveGenericType(paramsArrayType, NULL, genericArgumentsSubstitute);
|
||||||
|
|
||||||
|
if (paramsArrayType == NULL)
|
||||||
|
goto NoMatch;
|
||||||
|
|
||||||
if ((mArguments[argIdx].mArgFlags & BfArgFlag_ParamsExpr) != 0)
|
if ((mArguments[argIdx].mArgFlags & BfArgFlag_ParamsExpr) != 0)
|
||||||
{
|
{
|
||||||
// Direct-pass params
|
// Direct-pass params
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue