Replies: 6 comments 1 reply
-
Why should this be an error? The compiler synthesizes ToString for all records, right? So the method will be implemented. |
Beta Was this translation helpful? Give feedback.
-
I'd interpret abstract to mean "must be user provided in source", so a compiler-generated method shouldn't satisfy that. |
Beta Was this translation helpful? Give feedback.
-
Abstract means an override must be provided. The compiler provides that override. It has nothing to do with the user providing it or not :-) |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Obligatory "this could be an analyzer." Also, as a type author you can seal ToString in the base class (#4174) and have it call a new protected abstract member. |
Beta Was this translation helpful? Give feedback.
-
Version Used: dotnet/roslyn@98ea496
Steps to Reproduce:
Expected Behavior:
error CS0534: 'RecordBase.Record' does not implement inherited abstract member 'RecordBase.ToString()'
Actual Behavior: there's no error on the record declaration.
Beta Was this translation helpful? Give feedback.
All reactions