From 807a6ba51762021080fc549c69f0d9bcf807b294 Mon Sep 17 00:00:00 2001 From: McCall Saltzman Date: Mon, 3 Jun 2024 09:03:39 -0700 Subject: [PATCH 1/3] Add specific error case for on polymorphic types --- src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs | 7 +++++++ src/strings/PowerFxResources.en-US.resx | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs index 5f94a841cd..1754abfe97 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs @@ -3366,6 +3366,13 @@ public override void PostVisit(DottedNameNode node) var leftType = _txb.GetType(node.Left); + if (leftType.IsPolymorphic) + { + // Polymorphic is slightly different than the other cases below, this error contains specific suggestions on using AsType to get access to fields. + SetDottedNameError(node, TexlStrings.ErrInvalidDotOnPolymorphic); + return; + } + if (!leftType.IsControl && !leftType.IsAggregate && !leftType.IsEnum && !leftType.IsOptionSet && !leftType.IsView && !leftType.IsUntypedObject && !leftType.IsDeferred) { SetDottedNameError(node, TexlStrings.ErrInvalidDot, leftType.GetKindString()); diff --git a/src/strings/PowerFxResources.en-US.resx b/src/strings/PowerFxResources.en-US.resx index fef66154b4..fd5c8ce8c1 100644 --- a/src/strings/PowerFxResources.en-US.resx +++ b/src/strings/PowerFxResources.en-US.resx @@ -1866,6 +1866,10 @@ The '.' operator cannot be used on {0} values. Error Message. Error that occurs when you use the `.` operator on a type that doesn't support it. {0} is populated by a type name (e.g. Number, Text, Boolean). The operator (.) is not translated, should be the same character ('full stop', \u002E, decimal code 46) in all languages. + + The '.' operator cannot be used directly on Polymorphic lookups. Try using the AsType function to specify the type to treat it as. + {Locked=Polymorphic} {Locked=AsType} Error Message. Error that occurs when you use the `.` operator on a type that doesn't support it. Polymorphic is a type name. The operator (.) is not translated, should be the same character ('full stop', \u002E, decimal code 46) in all languages. + '{0}' is an unknown or unsupported function. Error Message. From 2e496cec412641ecb467255cf1d942810a51c3f9 Mon Sep 17 00:00:00 2001 From: McCall Saltzman Date: Mon, 3 Jun 2024 09:04:35 -0700 Subject: [PATCH 2/3] Missed a file --- src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs b/src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs index 91dfd8b815..34ef9213d6 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs @@ -613,6 +613,7 @@ internal static class TexlStrings public static ErrorResourceKey ErrTooManyUps = new ErrorResourceKey("ErrTooManyUps"); public static ErrorResourceKey ErrRuleNestedTooDeeply = new ErrorResourceKey("ErrRuleNestedTooDeeply"); public static ErrorResourceKey ErrInvalidDot = new ErrorResourceKey("ErrInvalidDot"); + public static ErrorResourceKey ErrInvalidDotOnPolymorphic = new ErrorResourceKey("ErrInvalidDotOnPolymorphic"); public static ErrorResourceKey ErrUnknownFunction = new ErrorResourceKey("ErrUnknownFunction"); public static ErrorResourceKey ErrUnimplementedFunction = new ErrorResourceKey("ErrUnimplementedFunction"); public static ErrorResourceKey ErrUnknownNamespaceFunction = new ErrorResourceKey("ErrUnknownNamespaceFunction"); From 684ccedf5dcb03f75a893a75c3807925d982e5af Mon Sep 17 00:00:00 2001 From: McCall Saltzman Date: Mon, 3 Jun 2024 10:04:33 -0700 Subject: [PATCH 3/3] casing --- src/strings/PowerFxResources.en-US.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strings/PowerFxResources.en-US.resx b/src/strings/PowerFxResources.en-US.resx index fd5c8ce8c1..109c0f0f51 100644 --- a/src/strings/PowerFxResources.en-US.resx +++ b/src/strings/PowerFxResources.en-US.resx @@ -1867,7 +1867,7 @@ Error Message. Error that occurs when you use the `.` operator on a type that doesn't support it. {0} is populated by a type name (e.g. Number, Text, Boolean). The operator (.) is not translated, should be the same character ('full stop', \u002E, decimal code 46) in all languages. - The '.' operator cannot be used directly on Polymorphic lookups. Try using the AsType function to specify the type to treat it as. + The '.' operator cannot be used directly on polymorphic lookups. Try using the AsType function to specify the type to treat it as. {Locked=Polymorphic} {Locked=AsType} Error Message. Error that occurs when you use the `.` operator on a type that doesn't support it. Polymorphic is a type name. The operator (.) is not translated, should be the same character ('full stop', \u002E, decimal code 46) in all languages.