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

Record structs: emit readonly modifier for synthesized members #54419

Closed
controlflow opened this issue Jun 26, 2021 · 2 comments · Fixed by #55039
Closed

Record structs: emit readonly modifier for synthesized members #54419

controlflow opened this issue Jun 26, 2021 · 2 comments · Fixed by #55039
Labels
Area-Compilers Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it New Language Feature - Records Records
Milestone

Comments

@controlflow
Copy link

Version Used:

main branch 26.06.2021

Steps to Reproduce:

Compile the following code:

public record struct A(int P) {
  public readonly void ReadOnlyMethod() {
    ToString(); // CS8656
    PrintMembers(null); // CS8656
    Equals(this); // CS8656
    Deconstruct(out _); // CS8656
    GetHashCode(); // CS8656
  }
}

Expected Behavior:

No compiler warning produced.

Actual Behavior:

Warnings like:

CS8656: Call to non-readonly member 'A.ToString()' from a 'readonly' member results in an implicit copy of 'this'.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 26, 2021
@RikkiGibson
Copy link
Contributor

We discussed this internally and decided we do want to make the change to make the synthesized record members readonly when possible. I drafted a spec change in dotnet/csharplang#4890.

@RikkiGibson RikkiGibson added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Jul 7, 2021
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 8, 2021
@jaredpar jaredpar added this to the 17.0 milestone Jul 8, 2021
@RikkiGibson
Copy link
Contributor

tagging @Youssef1313 just in case you find this issue interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it New Language Feature - Records Records
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants