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

Records won't warn about an unimplemented abstract ToString #76554

Closed
alrz opened this issue Dec 23, 2024 · 5 comments
Closed

Records won't warn about an unimplemented abstract ToString #76554

alrz opened this issue Dec 23, 2024 · 5 comments

Comments

@alrz
Copy link
Member

alrz commented Dec 23, 2024

Version Used: 98ea496

Steps to Reproduce:

abstract class ClassBase
{
    public abstract override string ToString();
    sealed class Class : ClassBase; // error
}
abstract record RecordBase
{
    public abstract override string ToString();
    sealed record Record : RecordBase; // ok (error expected)
}

Expected Behavior: error CS0534: 'RecordBase.Record' does not implement inherited abstract member 'RecordBase.ToString()'

Actual Behavior: there's no error on the record declaration.

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

Why should this be an error? The compiler synthesizes ToString for all records, right? So the method will be implemented.

@alrz
Copy link
Member Author

alrz commented Dec 23, 2024

I'd interpret abstract to mean "must be user provided in source", so a compiler-generated method shouldn't satisfy that.

@CyrusNajmabadi
Copy link
Member

Abstract means an override must be provided. The compiler provides that override. It has nothing to do with the user providing it or not :-)

@alrz
Copy link
Member Author

alrz commented Dec 23, 2024

Abstract means an override must be provided. The compiler provides that override. It has nothing to do with the user providing it or not :-)

And that's specified by the CIL. There's a lot of things that metadata doesn't care about but the language does. Like out/ref for example. I think this could be adjacent to that, only if you agree that it should be possible to reabstract record members that are inherited from object.

@CyrusNajmabadi
Copy link
Member

I don't know what you're asking for here. You said you thought this was a bug. I'm saying that i don't think this is a bug in the compiler, and the compiler is doing exactly the right thing as far as the language is concerned. At no point in the design of records did we say that if the base method is abstract that you would then have an error if the user didn't implement the method in source themselves.

If you want that, you'd need to propose a language change over at csharplang.

@alrz alrz converted this issue into a discussion Dec 23, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 23, 2024
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

2 participants