Adds the ForAll function for UntypedObjects. A very bizarre change with
some hacky type checking.
The problem is that overloaded functions with lambdas are not evaluated
bottom-up. This is because some of the arguments may be lambdas. It
leads to a chicken and egg problem: you need to know the override before
you can determine that an argument is a lambda, but you need to know
which arguments are lambdas in order to pick an override.
Thus we enforce that only a single override is allowed to have a lambda.
It is assumed to be a table, and we type check the first argument quite
late.
This implementation piggybacks off of all existing code paths by
"tricking" the type checker into thinking that there is only 1 override.
It will then "switch" the selected override at the last second if it's
discovered that the first argument is an untyped object.
Not ideal for a code maintenance standpoint. However, our other option
is to rename ForAll function to something else specifically for untyped
objects.
The IsNumeric function should return true for string values that represent, as well as to date, time and date/time values (which has a natural conversion to numbers)
New test to validate error kinds for all functions / operations. Also moved all finite checking to the function wrapper instead of having each function declare it
A recent change caused an exception to be thrown if an invalid tabular DateAdd function was used. This fixes it and adds a new test to check this scenario.
Currently some of the tabular versions of scalar functions are not calling the scalar version properly - instead of going to the function as exposed to the user (the wrapper that handles errors and blank values), it is going to the inner implementation. This PR updates the tabular versions for single argument functions (multi-argument functions will come later).
This also fixes the Char function to treat Blank values as 0, like Excel does.
This PR moves more date/time-related tests from the "notYetReady" folder
to run, and fixes a bunch of issues with date/time operations and
functions:
- Adding / subtracting numbers to date values now honors the fractional
part of the numbers (and the resulting type is DateTime)
- Similar fix for the DateAdd function with Date values
- Fixed time difference (timeValue1 - timeValue2)
- Allowed the addition of DateTime and Time values
- Allowed the addition of Time values
- Allowed the subtraction of time values from date[time] values
- Fixed Time function with overflows
Update UDF syntax:
- Equal for one expression formulas, consistent with named formulas
- No operator (no equal or double barrel arrow) for block functions
enclosed in curly braces, consistent with C-like languages
We have a few tests that are marked as skipped, but can run
successfully, so removing their #skip annotations. This also fixes blank
value comparison (and removes skipped tests for that).
A recent change to prevent delegation of Filter(TableA.Optionsetcolumn
in multiselectOptionset) (https://github.com/microsoft/Power-Fx/pull/522
) regressed a delegable scenario for singleSelectOptionSet in Collection
to be non delegable, adding an explicit check to not delegate if the in
operator is used on a async node instead of checking for !IsAggregate.
TestCases added in Client repo
Co-authored-by: Kartik K R <karr@microsoft.com>
Co-authored-by: McCall Saltzman <69215460+lesaltzm@users.noreply.github.com>
Such expression requires record to record coercion which wasn't
implemented
Patch(Table2, Lookup(Table2,
Table2=GUID("802dcedc-492f-ed11-9db2-0022482aea8f")), {MyDate:
"2022-9-14 7:11:04 pm" })
Before this fix, the error message we were returning was "unknown
error", now, it will provide a clear error message, asking for MyDate to
be a DateTime and not a string.
Support extensible CodeFixes.
Introduce a new class, EditorContextScope , to implement IPowerFxScope.
This lives in LSP.
Introduce new interface to supply code fix handlers:
```
public interface ICodeFixHandler
{
Task<IEnumerable<CodeActionResult>> SuggestFixesAsync(
Engine engine,
CheckResult checkResult);
}
```
And set:
```
var scope = engine.CreateEditorScope(symbols);
scope.AddQuickFixHandler(new MyCodeFixHandler()); // ICodeFixHandler
// return scope to IPowerFxScopeFactory
```
[0] Made RecalcEngineScope and supercede with a EditorContextScope.
Obsoleting this because:
- it creates an unnecssary dependy on RecalcEngine, instead of just
working with Engine class.
- hence lives in interpreter, when it should be in LSP.
- superseded by EditorContextScope, which has more editor
customizations.
- encourages a strong coupling on FromJson; but context is not json.
[1] CheckResult should have closure of its input args and serve as an
abstraction over the parse/bind results.
- add original parser text to CheckResult so that we don't have to pass
(expression,CheckResult) around.
- add Symbol table. internally, the Binding holds an INameResolve, so
it's consistent for CheckResult to hold the symbol table.
- input expression
- extra symbols (~binder has the INameResolver that it used)
This was useful in simplifying signatures. Then we can just do:
public IIntellisenseResult Suggest(CheckResult checkResult, int
cursorPosition)
[2] add ReadOnlySymbolTable.SymbolNames ?? *** rename , match to names?
[3] Expose some more spans, like Identifier.Span - which can be useful
in writing refactorings. *** as property
Co-authored-by: Mike Stall <jmstall@microsoft.com>
As a part of the feature I am working on , I need to modify the script
as below for all the tables, for that I will need all the table nodes.
`[{a: 1}, {a: 2}] -> [{value: {a:1}}, {value: {a:2}}]`
If the config has a chained symbol table:
powerFxConfig.SymbolTable = new SymbolTable() { Parent =
dataverseConnection.Symbols };
Then expressions like this get a null ref:
(IEnumStore) config.EnumStoreBuilder.Build(),
because config.EnumStoreBuilder is just
config.SymbolTable.EnumStoreBuilder, which is null.
It's not enough to just initialize SymbolTable.EnumStoreBuilder to
non-null, we need to ensure the symbols are actually composing.
This runs all Suggest tests in both configurations.
Marking config.EnumStoreBuilder as obsolete.
PowerApps doesn't call config.EnumStoreBuilder.
Dataverse does, but those call should config.EnumStore instead.
This was related to #503.
Co-authored-by: Mike Stall <jmstall@microsoft.com>
By default, Power FX is strongly + static typed. References to any
undefined fields will result in error state at type checking time.
This set of unit tests gives an example which overrides that behavior by
writing a custom `RecordType`, which always returns
`FormulaType.UntypedObject` from `TryGetField()` when the targeted field
is not defined.
Assume an expression `"obj.field1"`. If field1 is not defined, by
default it will throw at `Check()`. With this change, it will pass type
checking, and result in `BlankValue` (but of `UntypedObject` type)
during runtime.
Dataflow Analysis uses IErrorContainer instead of ErrorContainer. The
Binder utils does not need to use anything on the concrete class. So we
use the interface instead.
Blanks are currently treated as "false-y" values Boolean operators (Or, And), but not exactly false - there are some cases where blanks are returned (e.g., And(Blank(), true)). This PR changes the operators behavior so that the results of the expression above will be false.
EvalVisitor is not implemented on AggregateCoercionNode for records, but
the coercion matrix frequently produces this node in expressions like
'Patch(MyTable, { Currency: 1.2 }, { Currency: 1.5 })' when the Currency
column is a DType.Currency.
We should eventually implement RecordToRecord coercion, but as a first
stop, don't emit this coercion node if there actually aren't any
coercions used
Partially Reverts #465 which introduced a significant performance
regression.
This change reverts it, conditioned on a new flag added to
DocumentProperties. We'd like to remove this flag, and will once we've
adjusted the core Select/Expand behavior.
Continuing to move tests from the "NotYetReady" folder to the place
where they can actually run. Files starting with D. This is also fixing
some issues in the interpreter:
- DateDiff was not honoring date part boundaries
- Proper handling of blank values in DateAdd/DateDiff/Date functions
- Fix bug with DateAdd/DateDiff across daylight saving time boundaries
- Better errors for invalid dates
Binder can handle it automatically if flags are set properly. This also
imposes the same restrictions as powerapps.
Better way to solve #631 (better than #635)
This IExternal was incorrectly exposed on the public surface, but is not actually usable by any non-internal hosts, all the places it would be used are already `internal`. Thus, we think it's safe to make this breaking change.
Blank values should be treated as 0 when passed as the input to functions in numeric contexts. Currently the Sequence function doesn't do that, and this PR fixes it.
CheckEqualArgTypes
CheckComparisonArgTypes
CheckComparisonOneOf
These functions are all used by the PostVisit method for Binary op nodes and need to be made functional.
Also makes the PostVisit functions for both Binary and Unary op nodes more functional.
Continuing to move tests from the "NotYetReady" folder to the place where they can actually run. Files starting with B, and C. Also update how time values are compared in test results.
This started failing with #610.
Note in debug tests, we hit an Contract assert in binder in _binding.ResultType.
In PAClient, it uses retail FxCore, so contracts are disable, and hence we fail in