зеркало из https://github.com/microsoft/Power-Fx.git
Make FindBestErrorOverload a static helper for Binder (#743)
This is needed to share logic with Dataflow Analysis work
This commit is contained in:
Родитель
2d2afdd941
Коммит
fe591c598f
|
@ -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>
|
||||
|
|
Загрузка…
Ссылка в новой задаче