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

Compiler: thinks a local's type is that of another local #75710

Closed
KirillOsenkov opened this issue Nov 2, 2024 · 4 comments
Closed

Compiler: thinks a local's type is that of another local #75710

KirillOsenkov opened this issue Nov 2, 2024 · 4 comments
Assignees
Milestone

Comments

@KirillOsenkov
Copy link
Member

I'm seeing a recent regression in Csc, it wasn't there in 4.12.0-3.24463.9 but it is present in 4.12.0-3.24510.2 (Preview 5)

The symptoms are:

MetadataType.cs(411,36): error CS1061: 'IList<KeyValuePair<string, ulong>>' does not contain a definition for 'Attributes' and no accessible extension method 'Attributes' accepting a first argument of type 'IList<KeyValuePair<string, ulong>>' could be found (are you missing a using directive or an assembly reference?)

I can't find a standalone repro, but it looks like it thinks that a local's type is that of another local.

I can't share the repro publicly but ping me in private.

I think this is pretty bad.

@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 2, 2024
@jcouv jcouv added this to the 17.12 milestone Nov 3, 2024
@KirillOsenkov
Copy link
Member Author

Oops, I missed that there was a warning:

warning CS9258: In language version preview, the 'field' keyword binds to a synthesized backing field for the property. To avoid generating a synthesized backing field, and to refer to the existing member, use 'this.field' or '@field' instead.

In the code snippet, there was a local named field.

My apologies, this is by design.

Thanks @cston for investigating.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 4, 2024
@KirillOsenkov
Copy link
Member Author

Oh, and that explains why I couldn't find a simple repro: in the simple project I didn't set the LangVersion preview.

@miloush
Copy link

miloush commented Nov 4, 2024

ref: dotnet/csharplang#140 #74937
https://github.com/dotnet/csharplang/blob/main/proposals/field-keyword.md

especially for breaking changes dotnet/csharplang#7964

Why do we continue to allow var field = x; syntactically?

@CyrusNajmabadi
Copy link
Member

@miloush for language questions, please submit them at csharplang. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants