Revert "Allow CountIf and LookUp to coerce yes/no to Boolean (#187)" (#208)

* Revert "Allow CountIf and LookUp to coerce yes/no to Boolean (#187)"

This reverts commit 12b87ac778.

* Add test
This commit is contained in:
Carlos Figueira 2022-03-09 10:38:16 -08:00 коммит произвёл GitHub
Родитель 3aec136b84
Коммит 0b45b45865
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 9 добавлений и 27 удалений

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

@ -8,6 +8,7 @@ using Microsoft.PowerFx.Core.Entities;
using Microsoft.PowerFx.Core.Errors;
using Microsoft.PowerFx.Core.Functions;
using Microsoft.PowerFx.Core.Functions.Delegation;
using Microsoft.PowerFx.Core.Functions.Delegation.DelegationMetadata;
using Microsoft.PowerFx.Core.Localization;
using Microsoft.PowerFx.Core.Syntax.Nodes;
using Microsoft.PowerFx.Core.Types;
@ -21,7 +22,7 @@ namespace Microsoft.PowerFx.Core.Texl.Builtins
{
public override bool RequiresErrorContext => true;
public override bool SupportsParamCoercion => true;
public override bool SupportsParamCoercion => false;
public override DelegationCapability FunctionDelegationCapability => DelegationCapability.Filter | DelegationCapability.Count;
@ -63,17 +64,10 @@ namespace Microsoft.PowerFx.Core.Texl.Builtins
var fValid = CheckInvocation(args, argTypes, errors, out returnType, out nodeToCoercedTypeMap);
Contracts.Assert(returnType == DType.Number);
// Ensure that all the args starting at index 1 are booleans or can be coersed.
// Ensure that all the args starting at index 1 are booleans.
for (var i = 1; i < args.Length; i++)
{
if (CheckType(args[i], argTypes[i], DType.Boolean, DefaultErrorContainer, out var matchedWithCoercion))
{
if (matchedWithCoercion)
{
CollectionUtils.Add(ref nodeToCoercedTypeMap, args[i], DType.Boolean, allowDupes: true);
}
}
else
if (!DType.Boolean.Accepts(argTypes[i]))
{
errors.EnsureError(DocumentErrorSeverity.Severe, args[i], TexlStrings.ErrBooleanExpected);
fValid = false;

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

@ -5,7 +5,6 @@ using System.Collections.Generic;
using Microsoft.PowerFx.Core.App.ErrorContainers;
using Microsoft.PowerFx.Core.Binding;
using Microsoft.PowerFx.Core.Entities;
using Microsoft.PowerFx.Core.Errors;
using Microsoft.PowerFx.Core.Functions;
using Microsoft.PowerFx.Core.Functions.Delegation;
using Microsoft.PowerFx.Core.Functions.Delegation.DelegationMetadata;
@ -21,7 +20,7 @@ namespace Microsoft.PowerFx.Core.Texl.Builtins
{
public override bool RequiresErrorContext => true;
public override bool SupportsParamCoercion => true;
public override bool SupportsParamCoercion => false;
public LookUpFunction()
: base("LookUp", TexlStrings.AboutLookUp, FunctionCategories.Table, DType.Unknown, 0x6, 2, 3, DType.EmptyTable, DType.Boolean)
@ -48,20 +47,6 @@ namespace Microsoft.PowerFx.Core.Texl.Builtins
// The return type is dictated by the last argument (projection) if one exists. Otherwise it's based on first argument (source).
returnType = args.Length == 2 ? argTypes[0].ToRecord() : argTypes[2];
// Ensure that the arg at index 1 is boolean or can be coersed.
if (CheckType(args[1], argTypes[1], DType.Boolean, DefaultErrorContainer, out var matchedWithCoercion))
{
if (matchedWithCoercion)
{
CollectionUtils.Add(ref nodeToCoercedTypeMap, args[1], DType.Boolean, allowDupes: true);
}
}
else
{
errors.EnsureError(DocumentErrorSeverity.Severe, args[1], TexlStrings.ErrBooleanExpected);
fValid = false;
}
return fValid;
}

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

@ -20,4 +20,7 @@ Blank()
#Error
>> CountIf([1, 2, 0, 4, 5], 1/Value > 2)
#Error
#Error
>> CountIf([1, 2, 3, 4], 123)
Errors: Error 22-25: Invalid argument type (Number). Expecting a Boolean value instead.