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

Update field keyword breaking change diagnostics #76031

Open
cston opened this issue Nov 22, 2024 · 2 comments
Open

Update field keyword breaking change diagnostics #76031

cston opened this issue Nov 22, 2024 · 2 comments
Labels
Area-Compilers New Feature - Field Keyword untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@cston
Copy link
Member

cston commented Nov 22, 2024

With -langversion:preview, the token field, when used as a primary expression in a property accessor, binds to the synthesized backing field for the property. That is a breaking change when there is another symbol in scope named field that the compiler would have bound to with earlier language versions. The compiler reports a warning in -langversion:preview for those cases.

A couple of issues have been reported regarding the current warning:

  1. The warning does not match the Breaking change warnings proposal. In that proposal, warnings are reported in earlier language versions that the behavior will change rather than warning in later language versions that behavior has changed.

  2. The warning is reported for a reference to field, but not for a declaration of a local or parameter named field within the accessor, even though field will not bind to that variable. (To bind to the variable, use @field.)

We should consider updating the diagnostics to address these issues.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 22, 2024
@CyrusNajmabadi
Copy link
Member

The warning does not match the Breaking change warnings proposal

Yes. This seems important. We're using 'field ' to trial out the breaking change experience. So we should not deviate from the design there without good reason.

@jaredpar
Copy link
Member

The warning is reported for a reference to field, but not for a declaration of a local or parameter named field within the accessor, even though field will not bind to that variable. (To bind to the variable, use @field.)

I think that we need to draw inspiration from value here. Within an accessor it's not possible to declare a local named value because it would effectively shadow the implicit parameter. Given that we try and mirror field and value as much as possible, I think that we should error on local declarations. If you want to keep the local declaration then name it @field.

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

No branches or pull requests

3 participants