8000 Modernize pipe message models' nullability declarations. by plioi · Pull Request #321 · fixie/fixie · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Modernize pipe message models' nullability declarations. #321

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

Merged
merged 7 commits into from
Dec 16, 2023

Conversation

plioi
Copy link
Contributor
@plioi plioi commented Dec 16, 2023

When nullable reference types were first enabled, the PipeMessage message types presented an annoyance. Their setters were naturally public { get; set; }, though we wanted to declare the property types as non-null. Careful tracing of code paths confirmed that by the time they would be inspected, they really would be non-null. Having to mark them with ? would have needlessly spread unrealistic warnings to their usages, so instead we marked them all with the "confident assertion" { get; set; } = default!.

Since then C# has added two useful keywords which better help express and enforce the intention of these "serializable property bucket" types. Here we apply both of them:

  1. init as an alternative to set, communicating that they are intended to be populated during construction/initialization.
  2. required as an alternative to = default!, communicating that there is no need for a weak nullability assertion as the value will verifiably be assigned non-null upon initialization.

…del properties, as the method's reliance on the `new()` constraint is incompatible with applying `required`.

This entire change was performed by an automated refactoring.
… their intended use is to be fully populated upon construction and never changed.
…e set either in constructors or object initializer, instead of using the older fallback assertion `= default!`, allowing the compiler to vet that assertion.
@plioi plioi marked this pull request as ready for review December 16, 2023 16:14
@plioi plioi merged commit 399af25 into main Dec 16, 2023
@plioi plioi deleted the pipe-message-nullability branch December 16, 2023 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0