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

Fields generated from primary constructor parameters are incorrectly referenced by the Generate Equals and GetHashCode... codefix. #76916

Open
SleepWellPupper opened this issue Jan 24, 2025 · 0 comments
Assignees
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@SleepWellPupper
Copy link

Versions Used:
Compiler version: '4.12.0-3.24572.7 (dfa7fc6)'. Language version: preview.

Steps to Reproduce:

Applying the Generate Equals and GetHashCode... codefix to a type using primary ctor parameters captured in fields:

struct Foo(String a)
{
    public override String ToString() => a;
}

produces this dialog:

Image

and this generated code:

struct Foo(String a) : IEquatable<Foo>
{
    public override Boolean Equals(Object? obj) => obj is Foo foo && Equals(foo);
    public Boolean Equals(Foo other) => <a>P == other.<a>P;
    public override Int32 GetHashCode() => HashCode.Combine(<a>P);
    public override String ToString() => a;

    public static Boolean operator ==(Foo left, Foo right) => left.Equals(right);
    public static Boolean operator !=(Foo left, Foo right) => !( left  ==  right );
}

Expected Behavior:

The dialog, as well as the generated code use the user-facing primary ctor parameter name a.

Actual Behavior:

The dialog, as well as the generated code use the generated field name <a>P.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 24, 2025
@CyrusNajmabadi CyrusNajmabadi self-assigned this Jan 24, 2025
@CyrusNajmabadi CyrusNajmabadi added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 24, 2025
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Jan 24, 2025
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: InQueue
Development

No branches or pull requests

2 participants