Create an attribute that, when applied to a struct type, indicates that the default value of that struct is invalid #7632
Replies: 1 comment 1 reply
-
Closing, I think this should have been in the roslyn repo actually. Will recreate it there. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
With the latest versions of C# it is possible to override the default ctor for struct types which is useful to help prevent badly-formed struct-type values, but does not prevent usage of the default(T) value of a struct-type (either explicity or implicitly e.g. as part of an array or non-initialized class member).
Although the compiler can never fully prevent someone from creating a value of default(T), having an attribute we can apply to struct types that gives a hint would be useful. In these cases, where the compiler detects that a value will be default(T) for a type T that is annotated with this proposed attribute, it can emit a warning.
The compiler would only have to detect the most obvious cases-- but these would still be very useful in minimizing errors.
Examples always help, so here's an example:
Beta Was this translation helpful? Give feedback.
All reactions