From e1e538183ac75bf51cab8ad47616b927fe84b6de Mon Sep 17 00:00:00 2001 From: Shpakh-MSFT <10427420+Shpakh-MSFT@users.noreply.github.com> Date: Fri, 1 Nov 2024 06:11:10 -0700 Subject: [PATCH] =?UTF-8?q?Added=20new=20method=20on=20IExternalRule=20to?= =?UTF-8?q?=20help=20with=20invariantexpression=20ch=E2=80=A6=20(#2725)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On an effort to remove null rule binding, we need the ability to have an option to apply null binding before doing the check if binding is null. This change adds a new method on IExternalRule to help with that. --- .../Microsoft.PowerFx.Core/App/Controls/IExternalRule.cs | 3 +++ src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libraries/Microsoft.PowerFx.Core/App/Controls/IExternalRule.cs b/src/libraries/Microsoft.PowerFx.Core/App/Controls/IExternalRule.cs index 408dddfe4f..c29990ee9d 100644 --- a/src/libraries/Microsoft.PowerFx.Core/App/Controls/IExternalRule.cs +++ b/src/libraries/Microsoft.PowerFx.Core/App/Controls/IExternalRule.cs @@ -22,5 +22,8 @@ internal interface IExternalRule // Returns true when Binding is non-null, otherwise false. bool HasValidBinding { get; } + + // Returns true when rule is constant. + bool IsInvariantExpression { get; } } } diff --git a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs index 937173cb32..4dc0fa0e11 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs @@ -3619,9 +3619,7 @@ public override void PostVisit(DottedNameNode node) // 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.HasValidBinding && - !rule.HasErrorsOrWarnings && - rule.Binding.IsConstant(rule.Binding.Top)) + rule.IsInvariantExpression) { value = controlInfo; isConstant = true;