Skip to content

Commit

Permalink
PA errors fixing.
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-joyle committed Dec 30, 2024
1 parent 2857280 commit d71e7ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
43 changes: 8 additions & 35 deletions src/libraries/Microsoft.PowerFx.Core/Texl/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ 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(argTypes[i], exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules)) ||
(!context.Features.PowerFxV1CompatibilityRules && DType.String.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules))))
((!context.AnalysisMode && BuiltInEnums.RemoveFlagsEnum.FormulaType._type.Accepts(argType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules)) ||
(context.AnalysisMode && (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)))))
{
continue;
}
Expand All @@ -140,30 +141,17 @@ public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DTyp
(!context.Features.PowerFxV1CompatibilityRules && (!collectionAcceptsRecord && !recordAcceptsCollection)))
{
fValid = false;
SetErrorForMismatchedColumns(collectionType, argType, args[i], errors, context.Features);
if (!SetErrorForMismatchedColumns(collectionType, argType, args[i], errors, context.Features))
{
errors.EnsureError(DocumentErrorSeverity.Severe, args[i], TexlStrings.ErrTableDoesNotAcceptThisType);
}
}

// Only warn about no-op record inputs if there are no data sources that would use reference identity for comparison.
else if (!collectionType.AssociatedDataSources.Any() && !recordAcceptsCollection)
{
errors.EnsureError(DocumentErrorSeverity.Warning, args[i], TexlStrings.ErrCollectionDoesNotAcceptThisType);
}

if (!context.AnalysisMode)
{
// ArgType[N] (0<N<argCount) must match all the fields with the data source.
bool checkAggregateNames = argType.CheckAggregateNames(collectionType, args[i], errors, context.Features, SupportsParamCoercion);

// The item schema should be compatible with the collection schema.
if (!checkAggregateNames)
{
fValid = false;
if (!SetErrorForMismatchedColumns(collectionType, argType, args[i], errors, context.Features))
{
errors.EnsureError(DocumentErrorSeverity.Severe, args[i], TexlStrings.ErrTableDoesNotAcceptThisType);
}
}
}
}

returnType = context.Features.PowerFxV1CompatibilityRules ? DType.Void : collectionType;
Expand Down Expand Up @@ -382,23 +370,8 @@ public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DTyp
errors.EnsureError(args[1], TexlStrings.ErrNeedTable_Arg, args[1]);
}

if (!context.AnalysisMode)
{
bool checkAggregateNames = sourceType.CheckAggregateNames(collectionType, args[1], errors, context.Features, SupportsParamCoercion);

// The item schema should be compatible with the collection schema.
if (!checkAggregateNames)
{
fValid = false;
if (!SetErrorForMismatchedColumns(collectionType, sourceType, args[1], errors, context.Features))
{
errors.EnsureError(DocumentErrorSeverity.Severe, args[1], TexlStrings.ErrTableDoesNotAcceptThisType);
}
}
}

// The source schema should be compatible with the collection schema.
else if (!collectionType.Accepts(sourceType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) && !sourceType.Accepts(collectionType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules))
if (!collectionType.Accepts(sourceType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules) && !sourceType.Accepts(collectionType, exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules))
{
fValid = false;
if (!SetErrorForMismatchedColumns(collectionType, sourceType, args[1], errors, context.Features))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Error({Kind:ErrorKind.Div0})
Table({a:{aa:{aaa:true,bbb:true}}})

>> Remove(t4, {a:{aa:{aaa:true}}})
Errors: Error 0-6: The function 'Remove' has some invalid arguments.|Error 11-30: Missing column. Your formula is missing a column 'a.aa.bbb' with a type of 'Boolean'.|Error 11-30: Invalid argument type. Expecting a Record value, but of a different schema.|Error 11-30: Missing column. Your formula is missing a column 'aa.bbb' with a type of 'Boolean'.
Errors: Error 0-6: The function 'Remove' has some invalid arguments.|Error 11-30: Missing column. Your formula is missing a column 'a.aa.bbb' with a type of 'Boolean'.

>> Remove(t4, {a:{aa:{aaa:true,bbb:false}}})
Error({Kind:ErrorKind.NotFound})
Expand Down

0 comments on commit d71e7ad

Please sign in to comment.