microsoft / Power-Fx

Power Fx low-code programming language
MIT License
3.21k stars 327 forks source link

Collection fails with lazy types #2089

Closed MikeStall closed 11 months ago

MikeStall commented 11 months ago

See example here: https://github.com/microsoft/Power-Fx/compare/main...gekarapa:Power-Fx-PAP:test/lazytype-collect-testcase

MikeStall commented 11 months ago

Observations: The mismatch comes from Collect Function's CheckTypes at this callstack:

Microsoft.PowerFx.Core.dll!Microsoft.PowerFx.Core.Types.DType.Accepts(Microsoft.PowerFx.Core.Types.DType type, out System.Collections.Generic.KeyValuePair<string, Microsoft.PowerFx.Core.Types.DType> schemaDifference, out Microsoft.PowerFx.Core.Types.DType schemaDifferenceType, bool exact, bool useLegacyDateTimeAccepts, bool usePowerFxV1CompatibilityRules) Line 1924 C# Microsoft.PowerFx.Core.dll!Microsoft.PowerFx.Core.Types.DType.Accepts(Microsoft.PowerFx.Core.Types.DType type, bool exact, bool useLegacyDateTimeAccepts, bool usePowerFxV1CompatibilityRules) Line 1845 C# Microsoft.PowerFx.Core.dll!Microsoft.PowerFx.Core.Types.DType.LazyTypeAccepts(Microsoft.PowerFx.Core.Types.DType other, bool exact, bool usePowerFxV1CompatibilityRules) Line 1760 C# Microsoft.PowerFx.Core.dll!Microsoft.PowerFx.Core.Types.DType.Accepts(Microsoft.PowerFx.Core.Types.DType type, out System.Collections.Generic.KeyValuePair<string, Microsoft.PowerFx.Core.Types.DType> schemaDifference, out Microsoft.PowerFx.Core.Types.DType schemaDifferenceType, bool exact, bool useLegacyDateTimeAccepts, bool usePowerFxV1CompatibilityRules) Line 2149 C# Microsoft.PowerFx.Core.dll!Microsoft.PowerFx.Core.Types.DType.Accepts(Microsoft.PowerFx.Core.Types.DType type, bool exact, bool useLegacyDateTimeAccepts, bool usePowerFxV1CompatibilityRules) Line 1845 C# Microsoft.PowerFx.Core.dll!Microsoft.PowerFx.Core.Types.DType.TryGetCoercionSubType(Microsoft.PowerFx.Core.Types.DType expectedType, out Microsoft.PowerFx.Core.Types.DType coercionType, out bool coercionNeeded, Microsoft.PowerFx.Features features, bool safeCoercionRequired, bool aggregateCoercion) Line 3584 C# Microsoft.PowerFx.Interpreter.dll!Microsoft.PowerFx.Interpreter.CollectFunction.CheckTypes(Microsoft.PowerFx.Core.Functions.CheckTypesContext context, Microsoft.PowerFx.Syntax.TexlNode[] args, Microsoft.PowerFx.Core.Types.DType[] argTypes, Microsoft.PowerFx.Core.App.ErrorContainers.IErrorContainer errors, out Microsoft.PowerFx.Core.Types.DType returnType, out System.Collections.Generic.Dictionary<Microsoft.PowerFx.Syntax.TexlNode, Microsoft.PowerFx.Core.Types.DType> nodeToCoercedTypeMap) Line 197 C#

There is special handling that tries to make LazyType work. It will expand the lazy type to a concrete type with all fields, and then try to do the Accept comparison with concrete types.

It fails for 2 reasons:

If I fix both the above in the debugger, then the comparison succeeds and validates.