-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-Language DesignFeature RequestLanguage-C#Resolution-Won't FixA real bug, but Triage feels that the issue is not impactful enough to spend time on.A real bug, but Triage feels that the issue is not impactful enough to spend time on.Verification Not Required
Description
I know there's been a discussion on StackOverflow involving Eric Lippert on the potential problems with overriding the default() operator, but could it be implemented with additional restrictions?
- Overridden default() operator can return only a static readonly instance of the class or its subclass that have to be immutable. If the class is mutable, then the immutable subclass cannot access any base() methods or write to any fields/properties. Uh, I guess this is a whole 'nother issue, declaring immutability and asserting it by the compiler.
- If it's a struct, parameterless constructor must be equivalent to default().
- If it's a class, the compiler initializes all references to default() instead of null (I know it's slower, since you can't simply XOR the pointer with itself, but it's just copying a single value). Assigning null to it is rewritten to assigning default(T) by the compiler, the same with checking if it's null.
This way the consumer of the new class won't notice anything except the lack of NRE's.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Language DesignFeature RequestLanguage-C#Resolution-Won't FixA real bug, but Triage feels that the issue is not impactful enough to spend time on.A real bug, but Triage feels that the issue is not impactful enough to spend time on.Verification Not Required