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: [field:] should not be considered a backing field reference #75461

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

cston
Copy link
Member

@cston cston commented Oct 10, 2024

An attribute with a field: target used on a property accessor was incorrectly considered a reference to the backing field, resulting in a synthesized field for the property.

Fixes #75459.

@cston cston requested a review from a team as a code owner October 10, 2024 06:17
@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 10, 2024
var attributes = attributeList.Attributes;
for (int i = 0; i < attributes.Count; i++)
{
if (containsFieldExpressionInGreenNode(attributes[i]))
Copy link
Contributor

Choose a reason for hiding this comment

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

so is the idea that this way of visiting the syntax is skipping the attribute target?

Copy link
Member Author

@cston cston Oct 10, 2024

Choose a reason for hiding this comment

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

Yes, we're skipping the attribute target. I've since changed containsFieldExpressionInGreenNode() to look for FieldExpression rather than FieldToken, so this change is no longer strictly necessary, but it seemed reasonable to me to keep both changes.

@cston cston requested review from 333fred and a team October 10, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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.

Synthesized backing field generated for non-auto property with [field:] attribute
5 participants