Skip to content

Commit

Permalink
Added a new property on IExternalRule interface. (#2715)
Browse files Browse the repository at this point in the history
As PA is moving away from rules with null binding, this PR introduces a
new property called HasValidBinding which needs to be used to check the
binding validity in future rather than Binding property itself.
Eventually we should remove the Binding property from rule to abstract
that. This change is first step towards that direction.
  • Loading branch information
Shpakh-MSFT authored Oct 23, 2024
1 parent 05e865e commit ca42fbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ internal interface IExternalRule
TexlBinding Binding { get; }

bool HasErrorsOrWarnings { get; }

// Returns true when Binding is non-null, otherwise false.
bool HasValidBinding { get; }
}
}
7 changes: 5 additions & 2 deletions src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ internal IEnumerable<string> GetDataQuerySelects(TexlNode node)
return Enumerable.Empty<string>();
}

var ruleQueryOptions = Rule.Binding?.QueryOptions.GetQueryOptions(ds);
var ruleQueryOptions = Rule.HasValidBinding ? Rule.Binding.QueryOptions.GetQueryOptions(ds) : null;
if (ruleQueryOptions != null)
{
foreach (var nodeQO in Rule.TexlNodeQueryOptions)
Expand Down Expand Up @@ -3618,7 +3618,10 @@ public override void PostVisit(DottedNameNode node)
// If the reference is to Control.Property and the rule for that Property is a constant,
// we need to mark the node as constant, and save the control info so we may look up the
// rule later.
if (controlInfo?.GetRule(property.InvariantName) is IExternalRule rule && rule.Binding != null && !rule.HasErrorsOrWarnings && rule.Binding.IsConstant(rule.Binding.Top))
if (controlInfo?.GetRule(property.InvariantName) is IExternalRule rule &&
rule.HasValidBinding &&
!rule.HasErrorsOrWarnings &&
rule.Binding.IsConstant(rule.Binding.Top))
{
value = controlInfo;
isConstant = true;
Expand Down

0 comments on commit ca42fbc

Please sign in to comment.