Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
656 changes: 351 additions & 305 deletions src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/Public/Config/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public sealed class Features
/// </summary>
internal bool IsUserDefinedTypesEnabled { get; init; } = false;

/// <summary>
/// Enhanced checks for iteration functions (ForAll, Sum, AddColumns, ...) for:
/// 1. Recalc engine Set function is not allowed in the lambda of an iteration, in the same manner that
/// Clear and ClearCollect are not allowed. The Canvas Set function was already blocked.
/// 2. Global variables are blocked from self-modification, just as data sources have always been.
/// This became problematic when Canvas changed collection from being based on a data source to being based on a global variable.
/// This will break existing formulas and cannot be included in V1.
/// </summary>
internal bool EnhancedIterationChecks { get; init; }

internal static readonly Features None = new Features();

/// <summary>
Expand All @@ -100,6 +110,11 @@ public sealed class Features
IsUserDefinedTypesEnabled = true
};

public static readonly Features PowerFxV2 = new Features(_powerFxV1)
{
EnhancedIterationChecks = true
};

internal Features()
{
}
Expand All @@ -118,6 +133,7 @@ internal Features(Features other)
IsUserDefinedTypesEnabled = other.IsUserDefinedTypesEnabled;
AsTypeLegacyCheck = other.AsTypeLegacyCheck;
JsonFunctionAcceptsLazyTypes = other.JsonFunctionAcceptsLazyTypes;
EnhancedIterationChecks = other.EnhancedIterationChecks;
}
}
}
4 changes: 3 additions & 1 deletion src/libraries/Microsoft.PowerFx.Repl/Repl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class PowerFxREPL

public ParserOptions ParserOptions { get; set; } = new ParserOptions() { AllowsSideEffects = true };

public SymbolProperties VariableSymbolProperties { get; set; } = new SymbolProperties { CanMutate = true, CanSet = true };

// example override, switching to [1], [2] etc.
public virtual string Prompt => "\n>> ";

Expand Down Expand Up @@ -444,7 +446,7 @@ await this.Output.WriteLineAsync($"Error: Can't set '{name}' to a Void value.",
// Start as blank. Will execute expression below to actually assign.
var setValue = FormulaValue.NewBlank(setCheck.ReturnType);

this.Engine.UpdateVariable(name, setValue);
this.Engine.UpdateVariable(name, setValue, VariableSymbolProperties);

createdDeclarations = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ internal class TestDelegationMetadata : IDelegationMetadata

private readonly FilterOpMetadata _filterDelegationMetadata;

public TestDelegationMetadata(DelegationCapability capability = default, DType schema = default, Core.Functions.Delegation.DelegationMetadata.FilterOpMetadata filterDelegationMetadata = default)
private readonly SortOpMetadata _sortDelegationMetadata;

public TestDelegationMetadata(DelegationCapability capability = default, DType schema = default, FilterOpMetadata filterDelegationMetadata = default, SortOpMetadata sortDelegationMetadata = default)
{
_capability = capability;
_schema = schema ?? EntityRecordType._type;
_filterDelegationMetadata = filterDelegationMetadata;
_sortDelegationMetadata = sortDelegationMetadata;
}

public static RecordType EntityRecordType => RecordType.Empty()
Expand All @@ -62,7 +65,7 @@ public TestDelegationMetadata(DelegationCapability capability = default, DType s

public DelegationCapability TableCapabilities => _capability;

public SortOpMetadata SortDelegationMetadata => throw new NotImplementedException();
public SortOpMetadata SortDelegationMetadata => _sortDelegationMetadata;

public FilterOpMetadata FilterDelegationMetadata => _filterDelegationMetadata;

Expand Down Expand Up @@ -93,7 +96,7 @@ public bool TryGetEntity<T>(DName currentEntityEntityName, out T externalEntity)
if (_symbol.TryGetVariable(currentEntityEntityName, out NameLookupInfo lookupInfo, out _))
{
externalEntity = lookupInfo.Data as T;
return true;
return externalEntity != null;
}

return false;
Expand Down Expand Up @@ -197,7 +200,7 @@ internal TestDataSource(string name, DType schema, string[] keyColumns = null, I

public virtual bool IsDelegatable => throw new NotImplementedException();

public bool RequiresAsync => throw new NotImplementedException();
public bool RequiresAsync => false;

public IExternalDataEntityMetadataProvider DataEntityMetadataProvider => ExternalDataEntityMetadataProvider;

Expand All @@ -221,13 +224,13 @@ internal TestDataSource(string name, DType schema, string[] keyColumns = null, I

public BidirectionalDictionary<string, string> PreviousDisplayNameMapping => null;

public bool IsRefreshable => throw new NotImplementedException();
public bool IsRefreshable => true;

IDelegationMetadata IExternalDataSource.DelegationMetadata => DelegationMetadata;

public bool IsWritable => true;

public bool IsClearable => throw new NotImplementedException();
public bool IsClearable => true;

public bool CanIncludeExpand(IExpandInfo expandToAdd)
{
Expand Down
Loading
Loading