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

Field-backed properties: recognize field in interpolated string #75566

Merged
merged 5 commits into from
Oct 23, 2024

Conversation

cston
Copy link
Member

@cston cston commented Oct 20, 2024

Parse field as a keyword when used in an interpolated string in an accessor.
 
See dotnet/csharplang#140 (comment)

@cston cston requested a review from a team as a code owner October 20, 2024 19:01
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 20, 2024
Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests for field used in the alignment or format specifier sections of an interpolation. In particular, what will happen when there's a constant named field and field is used in the alignment section.

@cston cston requested a review from a team October 21, 2024 15:04
@@ -377,6 +378,7 @@ private static InterpolationSyntax ParseInterpolation(

// Now create a parser to actually handle the expression portion of the interpolation
using var tempParser = new LanguageParser(tempLexer, oldTree: null, changes: null);
using var __ = new FieldKeywordContext(tempParser, isInFieldKeywordContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why __ instead of simply _?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var __ was used for the other location in the parser to avoid conflicting with out _. Updated here.

var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("""
P1: True
2
"""));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider calling verifier.VerifyDiagnostics. Applies to the tests below as well.

@cston cston merged commit 0c28435 into dotnet:main Oct 23, 2024
24 checks passed
@cston cston deleted the field-interpolated-string branch October 23, 2024 15:53
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 23, 2024
@akhera99 akhera99 modified the milestones: Next, 17.13 P1 Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - Field Keyword untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants