Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-joyle committed Jan 9, 2025
1 parent d1106d8 commit 2461a45
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/libraries/Microsoft.PowerFx.Core/Texl/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Microsoft.PowerFx.Core.App.ErrorContainers;
using Microsoft.PowerFx.Core.Binding;
using Microsoft.PowerFx.Core.Entities;
Expand Down Expand Up @@ -49,7 +48,7 @@ public override bool TryGetTypeForArgSuggestionAt(int argIndex, out DType type)
return base.TryGetTypeForArgSuggestionAt(argIndex, out type);
}

public RemoveBaseFunction(int arityMax, params DType[] paramTypes)
public RemoveBaseFunction(int arityMax, params DType[] paramTypes)
: base("Remove", TexlStrings.AboutRemove, FunctionCategories.Behavior, DType.EmptyTable, 0, 2, arityMax, paramTypes)
{
}
Expand Down Expand Up @@ -99,6 +98,14 @@ public override bool IsAsyncInvocation(CallNode callNode, TexlBinding binding)

return Arg0RequiresAsync(callNode, binding);
}

public bool CheckEnumType(Features features, DType argType)
{
var enumValid = BuiltInEnums.RemoveFlagsEnum.FormulaType._type.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: features.PowerFxV1CompatibilityRules);

return (features.StronglyTypedBuiltinEnums && enumValid) ||
(!features.StronglyTypedBuiltinEnums && (DType.String.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: features.PowerFxV1CompatibilityRules) || enumValid));
}
}

// Remove(collection:*[], item1:![], item2:![], ..., ["All"])
Expand Down Expand Up @@ -167,10 +174,7 @@ public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DTyp

if (!argType.IsRecord)
{
if (argCount >= 3 && i == argCount - 1 &&
((context.Features.PowerFxV1CompatibilityRules && BuiltInEnums.RemoveFlagsEnum.FormulaType._type.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules)) ||
(!context.Features.PowerFxV1CompatibilityRules && (DType.String.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) ||
BuiltInEnums.RemoveFlagsEnum.FormulaType._type.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules)))))
if (argCount >= 3 && i == argCount - 1 && CheckEnumType(context.Features, argType))
{
continue;
}
Expand Down Expand Up @@ -368,9 +372,7 @@ public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DTyp
}
}

if (args.Length == 3 &&
((context.Features.PowerFxV1CompatibilityRules && !BuiltInEnums.RemoveFlagsEnum.FormulaType._type.Accepts(argTypes[2], exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules)) ||
(!context.Features.PowerFxV1CompatibilityRules && !DType.String.Accepts(argTypes[2], exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules))))
if (args.Length == 3 && !CheckEnumType(context.Features, argTypes[2]))
{
fValid = false;
errors.EnsureError(DocumentErrorSeverity.Severe, args[2], TexlStrings.ErrRemoveAllArg);
Expand Down

0 comments on commit 2461a45

Please sign in to comment.