[Proposal]: Nullable reference type checks should not be performed on members of abstract class #4359
Replies: 3 comments 36 replies
-
I kind of see your point, but I disagree. In my opinion, each field should be |
Beta Was this translation helpful? Give feedback.
-
This is covered by required properties. The abstract class will be able to require derived class to initialize the member, and it can be safely treated non-null. |
Beta Was this translation helpful? Give feedback.
-
I'm going to terminate the off-topic and focus on the original question. Nullability and abstract are contract, while fields are implementation.
Yes. It must be derived. However, there's no forcing about the derived class must initialize the non-null fields. Current contract is the base class constructor must initialize everything properly. Modifying the contract will require additional annotations, which is required fields/properties. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
FEATURE_NAME
Summary / Motivation
Currently, nullable reference checks are performed on non-private properties/fields of abstract classes.
Abstract classes, however, cannot be instantiated. Instead, a derived class must be implemented to get the abstract class to life.
So, I propose to omit corresponding nullable reference checks from the constructor of abstract classes and, instead, raise them to occur on constructors of derived, non-abstract, implementing classes:
Currently, it is required to assign redundant dummy values to such kind of properties/fields, which is cumbersome depending on the type of object to create. It doesn't add meaning to the code and bloats the result.
Beta Was this translation helpful? Give feedback.
All reactions