-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Aggregate types in UDF #2775
base: main
Are you sure you want to change the base?
Conversation
✅ No public API change. |
for (int i = 0; i < argTypes.Length; i++) | ||
{ | ||
if ((argTypes[i].IsTableNonObjNull || argTypes[i].IsRecordNonObjNull) && | ||
!ParamTypes[i].Accepts(argTypes[i], exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules, true) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
if ((argTypes[i].IsTableNonObjNull || argTypes[i].IsRecordNonObjNull) && | ||
!ParamTypes[i].Accepts(argTypes[i], exact: true, useLegacyDateTimeAccepts: false, usePowerFxV1CompatibilityRules: context.Features.PowerFxV1CompatibilityRules, true) && | ||
!argTypes[i].CoercesTo(ParamTypes[i], true, false, context.Features, true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -4221,6 +4221,10 @@ | |||
<value>The stated function return type '{0}' does not match the return type of the function body '{1}'.</value> | |||
<comment>This error message shows up when expected return type does not match with actual return type. The arguments '{0}' and '{1}' will be replaced with data types. For example, "The stated function return type 'Number' does not match the return type of the function body 'Table'"</comment> | |||
</data> | |||
<data name="ErrUDF_ReturnTypeSchemaDoesNotMatch" xml:space="preserve"> | |||
<value>The schema of stated function return type '{0}' does not match the schema of return type of the function body.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The schema of stated function return type '{0}' does not match the schema of return type of the function body
This message is a little confusing. In the example from the test f():T = {x: 5, y: 5}; T := Type({x: Number});
, the message will say something like "The schema of the state function return type 'Record' does not match the schema of return type of the function body" - but the maker did return a record. For example, we could say which field is extra / missing.
/// <returns> | ||
/// True if <see cref="DType"/> accepts <paramref name="type"/>, false otherwise. | ||
/// </returns> | ||
public bool Accepts(DType type, bool exact, bool useLegacyDateTimeAccepts, bool usePowerFxV1CompatibilityRules) | ||
public bool Accepts(DType type, bool exact, bool useLegacyDateTimeAccepts, bool usePowerFxV1CompatibilityRules, bool restrictiveAggregateTypes = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[InlineData( | ||
"f():T = {x: 5, y: 5}; T := Type({x: Number});", | ||
"", | ||
false)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to your changes, but since you are touching this file: this function is only used in this class (8 lines above). Can you make it private? Refers to: src/libraries/Microsoft.PowerFx.Core/Functions/UserDefinedFunction.cs:188 in 00c51ac. [](commit_id = 00c51ac, deletion_comment = False) |
Changes behavior of aggregate types like records and tables in User Defined Functions (UDFs)
Add stricter type checking (restrict allowing more fields than expected) for aggregate types in UDF argument and return.