Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific error case for . operator on polymorphic types #2452

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3386,6 +3386,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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/strings/PowerFxResources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,10 @@
<value>The '.' operator cannot be used on {0} values.</value>
<comment>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.</comment>
</data>
<data name="ErrInvalidDotOnPolymorphic" xml:space="preserve">
<value>The '.' operator cannot be used directly on polymorphic lookups. Try using the AsType function to specify the type to treat it as.</value>
<comment>{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.</comment>
</data>
<data name="ErrUnknownFunction" xml:space="preserve">
<value>'{0}' is an unknown or unsupported function.</value>
<comment>Error Message.</comment>
Expand Down
Loading