Make FindBestErrorOverload a static helper for Binder (#743)

This is needed to share logic with Dataflow Analysis work
This commit is contained in:
McCall Saltzman 2022-10-07 16:20:35 -07:00 коммит произвёл GitHub
Родитель 2d2afdd941
Коммит fe591c598f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 24 добавлений и 24 удалений

Просмотреть файл

@ -4919,30 +4919,6 @@ namespace Microsoft.PowerFx.Core.Binding
}
}
/// <summary>
/// Returns best overload in case there are no matches based on first argument and order.
/// </summary>
private TexlFunction FindBestErrorOverload(TexlFunction[] overloads, DType[] argTypes, int cArg)
{
var candidates = overloads.Where(overload => overload.MinArity <= cArg && cArg <= overload.MaxArity);
if (cArg == 0)
{
return candidates.FirstOrDefault();
}
// Consider overloads that have DType.Error parameter the last
candidates = candidates.OrderBy(candidate => candidate.ParamTypes.Length > 0 && candidate.ParamTypes[0] == DType.Error).ToArray();
foreach (var candidate in candidates)
{
if (candidate.ParamTypes.Length > 0 && candidate.ParamTypes[0].Accepts(argTypes[0]))
{
return candidate;
}
}
return candidates.FirstOrDefault();
}
private void PreVisitWithOverloadResolution(CallNode node, TexlFunction[] overloads)
{
Contracts.AssertValue(node);

Просмотреть файл

@ -176,6 +176,30 @@ namespace Microsoft.PowerFx.Core.Binding
return false;
}
/// <summary>
/// Returns best overload in case there are no matches based on first argument and order.
/// </summary>
internal static TexlFunction FindBestErrorOverload(TexlFunction[] overloads, DType[] argTypes, int cArg)
{
var candidates = overloads.Where(overload => overload.MinArity <= cArg && cArg <= overload.MaxArity);
if (cArg == 0)
{
return candidates.FirstOrDefault();
}
// Consider overloads that have DType.Error parameter the last
candidates = candidates.OrderBy(candidate => candidate.ParamTypes.Length > 0 && candidate.ParamTypes[0] == DType.Error).ToArray();
foreach (var candidate in candidates)
{
if (candidate.ParamTypes.Length > 0 && candidate.ParamTypes[0].Accepts(argTypes[0]))
{
return candidate;
}
}
return candidates.FirstOrDefault();
}
/// <summary>
/// Helper for Lt/leq/geq/gt type checking. Restricts type to be one of the provided set, without coercion (except for primary output props).
/// </summary>