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

Revise CompilerGeneratedAttribute behavior when records are inherited #61991

Closed
Youssef1313 opened this issue Jun 17, 2022 · 3 comments · Fixed by #61993
Closed

Revise CompilerGeneratedAttribute behavior when records are inherited #61991

Youssef1313 opened this issue Jun 17, 2022 · 3 comments · Fixed by #61993
Assignees
Milestone

Comments

@Youssef1313
Copy link
Member

using System;
using System.Linq;

var hashCodeAttributes = typeof(RR).GetMethod("GetHashCode").GetCustomAttributes(inherit: true);
// prints: "System.Runtime.CompilerServices.CompilerGeneratedAttribute"
// It prints "No attributes" if `inherit: true` is changed to `false`.
Console.WriteLine(hashCodeAttributes.Length == 0 ? "No attributes" : hashCodeAttributes.Single());

record R
{
}

record RR : R
{
    public override int GetHashCode()
    {
        return 0;
    }
}

Is this behavior okay? @jcouv

@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 17, 2022
@jcouv
Copy link
Member

jcouv commented Jun 17, 2022

I think that's okay. CompilerGeneratedAttribute has Inherited=true, so when using the GetCustomAttributes API with inherit: true option, it will show up.

[System.AttributeUsage(System.AttributeTargets.All, Inherited=true)]
public sealed class CompilerGeneratedAttribute : Attribute

@jcouv jcouv added the Resolution-By Design The behavior reported in the issue matches the current design label Jun 17, 2022
@Youssef1313
Copy link
Member Author

@jcouv So it seems #58542 (comment) no longer holds. So should we move the attribute back to the property instead of accessors?

@jcouv
Copy link
Member

jcouv commented Jun 17, 2022

@Youssef1313 That would make sense. I hadn't connected those dots.

@jcouv jcouv removed the Resolution-By Design The behavior reported in the issue matches the current design label Jun 22, 2022
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jun 22, 2022
@jcouv jcouv added this to the C# 11.0 milestone Jun 22, 2022
@jcouv jcouv added the Bug label Jun 22, 2022
@jaredpar jaredpar modified the milestones: C# 11.0, 17.4 Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants